我正在使用以下代码并排生成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
我生成以下可视化但是条之间的距离非常高。如何减小宽度?
答案 0 :(得分:2)
问题在于您使用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="")