删除两个ggplots与grid.arrange结合使用的所有空间 [英] removing all the space between two ggplots combined with grid.arrange

查看:163
本文介绍了删除两个ggplots与grid.arrange结合使用的所有空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



鉴于:

  p1 < -  qplot(1,1,xlab =)

p1 < - p1 +
主题position =none,
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
plot.margin = unit(c(1,1, 0,1),cm),
panel.margin =单位(c(1,1,0,1),cm))
p2 < - qplot(1,2)

grid.arrange(p1,p2)

p>



我想消除两块地块之间的空白区。



我的印象调整了高度, 左对齐两个图形边缘(ggplot)是解决方案,但无法弄清楚。

plot.margin ,并为p1的下边距和p2的上边距设置负值。这将确保两个图连接。

  p1 < -  qplot(1,1,xlab =)+ 
theme(legend.position =none,
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
plot.margin = unit( c(1,1,-0.5,1),cm))
p2 < - qplot(1,2)+
theme(legend.position =none,
plot.margin = unit(c(-0.5,1,1,1),cm))


grid.arrange(p1,p2)


I want to stick two plots without any space between theme (so they share one axis).

Given:

p1 <- qplot(1,1,xlab="")

p1 <- p1 +
  theme(legend.position="none",
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        plot.margin=unit(c(1,1,0,1), "cm"),
        panel.margin=unit(c(1,1,0,1), "cm"))
p2 <- qplot(1,2)

grid.arrange(p1,p2)

Which produces:

I want to eliminate the white space between the two plots.

I have the impression tweaking heights, as has been done for widths in : left align two graph edges (ggplot) is the solution, but can't figure it out.

解决方案

You should provide plot.margin for both plots and set negative value for the bottom margin for p1 and upper margin for p2. This will ensure that both plot joins.

p1 <-  qplot(1,1,xlab="")+
  theme(legend.position="none",
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        plot.margin=unit(c(1,1,-0.5,1), "cm"))
p2 <- qplot(1,2)+
  theme(legend.position="none",
        plot.margin=unit(c(-0.5,1,1,1), "cm"))


grid.arrange(p1,p2)

这篇关于删除两个ggplots与grid.arrange结合使用的所有空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆