grid.arrange():整齐排列3个绘图
我想安排3个正方形的图,其中一个较大,另外两个较小,与第一个一起 以下是我的尝试:grid.arrange():整齐排列3个绘图,r,ggplot2,R,Ggplot2,我想安排3个正方形的图,其中一个较大,另外两个较小,与第一个一起 以下是我的尝试: gg1 <- ggplot(mtcars,aes(x=hp,y=mpg))+ geom_point(aes(color=factor(cyl)),alpha=.5)+ stat_smooth(method='lm', se=F, color='red')+ ggtitle('plot 1')+ theme_bw()+ theme
gg1 <- ggplot(mtcars,aes(x=hp,y=mpg))+
geom_point(aes(color=factor(cyl)),alpha=.5)+
stat_smooth(method='lm', se=F, color='red')+
ggtitle('plot 1')+
theme_bw()+
theme(aspect.ratio=1,
legend.position = c(1, 1),
legend.justification = c(1,1),
legend.background = element_rect(colour = NA, fill = NA))
gg2 <- ggplot(mtcars)+
geom_density(aes(x=hp, color=factor(cyl)))+
ggtitle('plot 2')+
theme_bw()+
theme(aspect.ratio=1,
legend.position = c(1, 1),
legend.justification = c(1,1),
legend.background = element_rect(colour = NA, fill = NA))
gg3 <- ggplot(mtcars)+
geom_density(aes(x=mpg, color=factor(cyl)))+
ggtitle('plot 3')+
theme_bw()+
theme(aspect.ratio=1,
legend.position = c(1, 1),
legend.justification = c(1,1),
legend.background = element_rect(colour = NA, fill = NA))
grid.arrange(arrangeGrob(gg1),
arrangeGrob(gg2,gg3, ncol=1),
ncol=2, widths=c(1,1))
我得到了这样的东西
关于如何管理整齐的排列有什么想法吗?我总是使用
arrangeGrob
函数将所有内容放入变量中,并使用ggsave
保存此对象
a <- arrangeGrob(arrangeGrob(gg1), arrangeGrob(gg2,gg3, ncol=1), ncol=2, widths=c(2,1))
# big plot should be twice wider than two small ones
ggsave('~/Downloads/jnk.pdf',a)
ggsave('~/Downloads/jnk.png',a) #in case of png file.
a不能解决问题,在任何情况下,我希望宽度类似于c(2,1)。老实说,我没有完全阅读我刚刚意识到的问题,但是是的,widths=c(2,1)
解决了它:-)
a <- arrangeGrob(arrangeGrob(gg1), arrangeGrob(gg2,gg3, ncol=1), ncol=2, widths=c(2,1))
# big plot should be twice wider than two small ones
ggsave('~/Downloads/jnk.pdf',a)
ggsave('~/Downloads/jnk.png',a) #in case of png file.