【发布时间】:2015-05-18 16:41:28
【问题描述】:
我尝试使用 gridExtra 包排列两个具有不同绘图高度但绘图宽度相同的 ggplots。
我有一个相同宽度或相同高度的解决方案,但我无法同时实现。
这是我的代码:
require(ggplot2)
require(gridExtra)
set.seed(987)
dat <- data.frame(x = 1:100,
y1 = rnorm(100),
y2 = rnorm(100)*1e6)
p1 <- ggplot(dat, aes(x = x, y = y1)) +
geom_point() + ylab("")
p2 <- ggplot(dat, aes(x = x, y = y2)) +
geom_point() + ylab("")
# Arrange Plots
# Version 1
# same widths, same heights
grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2), size = "last"))
# Version 2
# different heights, different widths
grid.arrange(p1, p2, ncol = 1, heights = c(2, 1))
结果如下:
版本 1:宽度相同但高度不同
版本 2:不同的高度但不同的绘图宽度
但是,我想要组合:相同的宽度,但不同的高度。您对在这种情况下如何组合 grid.draw 和 grid.arrange 有任何想法吗?
【问题讨论】:
-
意思是尽可能重复:stackoverflow.com/q/23863345/903061