3

ggplot2 を使用して散布図をプロットしています。スケールを非表示にすると、プロットが自動的に少し大きくなります。例えば:

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
geom_point() +
theme(axis.title.x = element_blank(),
      axis.title.y = element_blank(),
      legend.position = "none")

2つ目はもっと大きいです。どうすれば回避できますか?スケールとラベルのみを非表示にしたいが、プロットを最初のものとして保持します。これは、スケールのあるものとないものの2つを結合したいが、プロットのサイズを同じに保ちたいからです。ありがとう。

4

1 に答える 1

4

トリッキーですが動作します。白の軸

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()

+ theme (axis.title.x = element_text(family = "sans", face = "bold"))
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
  geom_point() +
  theme(axis.title.x = element_text(family = "sans", face = "bold",colour='white'))+
  theme(axis.title.y = element_text(family = "sans", face = "bold",colour='white'))

編集:一般的な解決策

p1 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()

p2 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
  geom_point() +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        legend.position = "none")

gA <- ggplot_gtable(ggplot_build(p1))
gB <- ggplot_gtable(ggplot_build(p2))
gA$widths  <- gB$widths
gA$heights <- gB$heights

plot(gA)
plot(gB)
于 2012-12-04T20:24:25.527 に答える