30

テーマ間にスペースを入れずに 2 つのプロットを貼り付けたい (したがって、1 つの軸を共有する)。

与えられた:

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)

生成するもの:

ここに画像の説明を入力

2 つのプロット間の空白を削除したい。

の幅に対して行われたように、高さを微調整している印象があります。2つのグラフの端を左揃えにする(ggplot)が解決策ですが、それを理解できません。

4

2 に答える 2

42

両方のプロットを用意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)

ここに画像の説明を入力してください

于 2013-03-21T19:13:49.100 に答える
0

試す

+ labs(x=NULL)

また

+ labs(x=NULL, y=NULL)

grid.arrange を使用する前に、プロット (p1、p2) の周囲の左マージンと下マージンを削除します。

p1 <- qplot(1,1)+
 theme_bw() +
 theme(axis.text.x=element_blank(),
 axis.ticks.x=element_blank(),
 plot.margin = rep(unit(0,"null"),4),
 panel.margin = unit(0,"null"),
 axis.ticks.length = unit(0,"null"),
 axis.ticks.margin = unit(0,"null")) +
 labs(x=NULL)
p2 <- qplot(1,2)+
 theme_bw() +
 theme(
 plot.margin = rep(unit(0,"null"),4),
 panel.margin = unit(0,"null"),
 axis.ticks.length = unit(0,"null"),
 axis.ticks.margin = unit(0,"null"))

grid.arrange(p1,p2)
于 2013-06-17T13:41:08.113 に答える