こんにちは、R と ggplot2 コミュニティです。
で作成された 2 つのプロットを水平方向に並べたいと思いggplot2
ます。1 つにはファセット (およびファセット ストリップ!) と凡例の両方がありますが、2 つ目はありません。それらは同じ Y 軸を共有しており、これを揃えたいと考えています。グロブの幅を使用してプロットを垂直方向に配置しても問題ありませんが、高さではわかりませんでした。
ここに私の質問をサポートするコードがあります。
library( ggplot2 )
library( gridExtra )
plot_1 <- ggplot() +
geom_point(
data = iris,
aes(
x = Petal.Length,
y = Petal.Width,
colour = Sepal.Length
)
) +
facet_grid(
. ~ Species
) +
theme(
legend.position = "bottom"
)
plot_2 <- ggplot() +
geom_point(
data = iris,
aes(
x = Sepal.Width,
y = Petal.Width
)
)
g1 <- ggplotGrob( plot_1 )
g2 <- ggplotGrob( plot_2 )
# Here, how to manipulate grobs to get plot_2 scaled to the plot_1's Y axis? (ie, with an empty area right of the plot_1's legend)
grid.arrange( g1, g2, ncol = 2 )
以前にグロブの高さを操作する方法を知っていますgrid.arrange()
か? (他の提案は大歓迎です!) さらに、たとえば総面積の 3 分の 2 を に割り当てる方法はplot_1
?
私の実際のプロットには実際には が含まれていることにも注意してください。ただしcoord_flip()
、この質問には関係ないと思います。
ご協力いただきありがとうございます!