【发布时间】:2015-12-29 17:55:18
【问题描述】:
给定两个 ggplots,我们可以并排排列它们
library(ggplot2)
library(gridExtra)
# Data
data(iris)
df <- data.frame(y = rnorm(100))
# Plotting
p1 <- qplot(data=iris, Sepal.Width, Sepal.Length)
p2 <- ggplot(df, aes(x=1:100, y=y)) + geom_line()
grid.arrange(p1, p2, ncol=2)
如果其中一个图是ggpair 对象,我们该怎么做?
library(GGally)
p1 <- ggpairs(iris, colours='Species')
p2 <- ggplot(df, aes(x=1:100, y=y)) + geom_line()
grid.arrange(l, p2, ncol=6)
# Error in gList(list(list(data = list(Sepal.Length = c(5.1, 4.9, 4.7,
# 4.6, : only 'grobs' allowed in "gList"
【问题讨论】:
-
如需快捷方式,您可以使用Baptistes answer from here。因此,如果
p1在您的绘图窗口中,library(gridGraphics) ; g <- grid.grab() ; grid.arrange(g, p2, widths=c(0.8,0.2)) -
请参阅stackoverflow.com/questions/24135157/… 了解有关使用 grid.arrange 的讨论