我想在主题之间没有任何空格的情况下粘贴两个图(因此它们共享一个轴)。
鉴于:
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)
其中产生:
我想消除两个图之间的空白。
我有调整高度的印象,正如对宽度所做的那样:left align two graph edges (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)
关于结合 grid.arrange 删除两个 ggplots 之间的所有空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15556068/