【发布时间】:2018-11-09 17:17:44
【问题描述】:
我有一个奇怪的问题,我正在使用 par() 制作多面板条形图,我注意到条形图的大小不同,我想知道是否可以使条形图的宽度(大小)相同每个面板?这将创建不同大小的面板,但这很好。任何 cmets 都会有所帮助。
我有这个通用的例子:
# create data
a<-c(1:100)
b<-c(1:200)
c<-c(1:300)
d<-c(1:400)
e<-c(1:500)
#make dataframes for barplots
test<-as.data.frame(cbind(a,b))
test1<-as.data.frame(cbind(a,b,c))
test2<-as.data.frame(cbind(a,b,c,d))
test3<-as.data.frame(cbind(a,b,c,d,e))
#gets means for each column
a1<-colMeans(test)
a2<-colMeans(test1)
a3<-colMeans(test2)
a4<-colMeans(test3)
#lets plot
pdf(file= "/Users/Highf_000/Desktop/prac.pdf");
par(mfrow = c(2, 4), # 2 rows x 4 columns layout
oma = c(2, 2, 0, 0), # two rows of text at the outer left and bottom margin
mar = c(5, 5, 2, 1)+0.1, # space for one row of text at ticks and to separate plots
mgp = c(2, 1, 0), # axis label at 2 rows distance, tick labels at 1 row
xpd = NA)
barplot(mean(a))
barplot(a1)
barplot(a2)
barplot(a3)
barplot(a4)
dev.off()
我们如何克服在多情节布局中情节消失的问题,以及如何将标题固定在条形而不是情节的中心?
【问题讨论】:
-
这个问题已经有答案了,请看this post
-
@Rebecca,你能解释一下 xlim 和 width 命令是如何工作的吗?