如何减小格子条形图中条形之间的宽度?
How to decrease the width between bars in lattice bar chart?
我正在使用以下代码并排生成 10 个条形图。
library(reshape2)
library(lattice)
data <- read.csv("/Users/.../data.csv", sep = ",")
df.long<-melt(data,id.vars=c("Vis","Task"))
df.long
barchart(Vis~value|Task,
groups=Vis,data=df.long,layout=c(5,2),
between = list(y=0.2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) ),
box.ratio = 1/4,
box.width = 1
)
这是我的 csv 格式数据。
Vis,Accuracy,Task
Bar chart,66,Anomalies
Line chart,52,Anomalies
Pie chart,80,Anomalies
Scatterplot,52,Anomalies
Table,66,Anomalies
Bar chart,100,Cluster
Line chart,33,Cluster
Pie chart,100,Cluster
Scatterplot,60,Cluster
Table,93,Cluster
Bar chart,90,Correlation
Line chart,30,Correlation
Pie chart,40,Correlation
Scatterplot,80,Correlation
Table,70,Correlation
Bar chart,73,Derived
Line chart,80,Derived
Pie chart,66,Derived
Scatterplot,86,Derived
Table,100,Derived
Bar chart,46,Distribution
Line chart,60,Distribution
Pie chart,60,Distribution
Scatterplot,73,Distribution
Table,46,Distribution
Bar chart,100,Extremum
Line chart,77.7,Extremum
Pie chart,94,Extremum
Scatterplot,61,Extremum
Table,88.8,Extremum
Bar chart,100,Filter
Line chart,75,Filter
Pie chart,100,Filter
Scatterplot,83,Filter
Table,83,Filter
Bar chart,75,Order
Line chart,66,Order
Pie chart,50,Order
Scatterplot,58,Order
Table,59,Order
Bar chart,40,Range
Line chart,66.6,Range
Pie chart,100,Range
Scatterplot,93,Range
Table,93,Range
Bar chart,91,Retrieve
Line chart,66,Retrieve
Pie chart,100,Retrieve
Scatterplot,75,Retrieve
Table,100,Retrieve
我生成了以下可视化效果,但条形之间的距离非常高。我怎样才能减少宽度?
问题是您将 Vis
同时用作 y 变量和分组变量。这在晶格中效果不佳。最简单的修复可能只是制作一个堆叠的条形图。
barchart(Vis~value|Task,
groups=Vis,
stack=T,
data=df.long,
layout=c(5,2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) )
)
您也可以从 y 轴上删除 Vis,您基本上是用颜色图例对其进行双重标记。
barchart(~value|Task,
groups=Vis,
data=df.long,
layout=c(5,2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) )
)
这是点阵绘图系统的一个弱点。你可以用 ggplot 更容易地做这样的事情
库(ggplot2)
ggplot(df.long, aes(Vis, value, fill=Vis)) +
geom_bar(stat='identity') +
coord_flip() + facet_wrap(~Task, ncol=5) +
theme(legend.position="top") +
scale_fill_discrete(name="")
我正在使用以下代码并排生成 10 个条形图。
library(reshape2)
library(lattice)
data <- read.csv("/Users/.../data.csv", sep = ",")
df.long<-melt(data,id.vars=c("Vis","Task"))
df.long
barchart(Vis~value|Task,
groups=Vis,data=df.long,layout=c(5,2),
between = list(y=0.2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) ),
box.ratio = 1/4,
box.width = 1
)
这是我的 csv 格式数据。
Vis,Accuracy,Task
Bar chart,66,Anomalies
Line chart,52,Anomalies
Pie chart,80,Anomalies
Scatterplot,52,Anomalies
Table,66,Anomalies
Bar chart,100,Cluster
Line chart,33,Cluster
Pie chart,100,Cluster
Scatterplot,60,Cluster
Table,93,Cluster
Bar chart,90,Correlation
Line chart,30,Correlation
Pie chart,40,Correlation
Scatterplot,80,Correlation
Table,70,Correlation
Bar chart,73,Derived
Line chart,80,Derived
Pie chart,66,Derived
Scatterplot,86,Derived
Table,100,Derived
Bar chart,46,Distribution
Line chart,60,Distribution
Pie chart,60,Distribution
Scatterplot,73,Distribution
Table,46,Distribution
Bar chart,100,Extremum
Line chart,77.7,Extremum
Pie chart,94,Extremum
Scatterplot,61,Extremum
Table,88.8,Extremum
Bar chart,100,Filter
Line chart,75,Filter
Pie chart,100,Filter
Scatterplot,83,Filter
Table,83,Filter
Bar chart,75,Order
Line chart,66,Order
Pie chart,50,Order
Scatterplot,58,Order
Table,59,Order
Bar chart,40,Range
Line chart,66.6,Range
Pie chart,100,Range
Scatterplot,93,Range
Table,93,Range
Bar chart,91,Retrieve
Line chart,66,Retrieve
Pie chart,100,Retrieve
Scatterplot,75,Retrieve
Table,100,Retrieve
我生成了以下可视化效果,但条形之间的距离非常高。我怎样才能减少宽度?
问题是您将 Vis
同时用作 y 变量和分组变量。这在晶格中效果不佳。最简单的修复可能只是制作一个堆叠的条形图。
barchart(Vis~value|Task,
groups=Vis,
stack=T,
data=df.long,
layout=c(5,2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) )
)
您也可以从 y 轴上删除 Vis,您基本上是用颜色图例对其进行双重标记。
barchart(~value|Task,
groups=Vis,
data=df.long,
layout=c(5,2),
auto.key = list(rectangles = TRUE, space = 'top', columns = 5),
origin = 0,
par.settings = list(fontsize=list(text=8) )
)
这是点阵绘图系统的一个弱点。你可以用 ggplot 更容易地做这样的事情
库(ggplot2)
ggplot(df.long, aes(Vis, value, fill=Vis)) +
geom_bar(stat='identity') +
coord_flip() + facet_wrap(~Task, ncol=5) +
theme(legend.position="top") +
scale_fill_discrete(name="")