删除两个ggplots之间的所有空间以及grid.arrange

Eti*_*rie 24 r ggplot2

我想在主题之间插入两个没有任何空间的图(因此它们共用一个轴).

鉴于:

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)
Run Code Online (Sandbox Code Playgroud)

哪个产生:

在此输入图像描述

我想消除两个地块之间的空白区域.

我有调整高度的印象,就像宽度所做的那样:左对齐两个图形边缘(ggplot)是解决方案,但无法弄明白.

Did*_*rts 35

您应该提供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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述