【发布时间】:2017-07-17 06:57:29
【问题描述】:
有没有办法以交互方式和顺序将更多 ggplots 添加到绘图窗口,类似于在 base 中您可以使用 par(mfrow = ...) 添加更多绘图。例如。 (for循环模拟顺序输入的绘图命令):
par(mfrow = c(4, 1))
for (i in 1:4) {
plot(tmp_df$x, tmp_df$y)
}
依次生成下图的第一行到最后一行:
而对ggplot 执行相同操作只会在绘图窗口中打印一个绘图:
par(mfrow = c(4, 1))
for (i in 1:4) {
plot(ggplot(tmp_df, aes(x, y)) +
geom_point())
}
我已经知道如何使用gridExtra::grid.arrange来排列ggplots的列表,例如:
tmp_list <- list()
for (i in 1:4) {
tmp_list[[length(tmp_list) + 1]] <-
ggplot(tmp_df, aes(x, y)) +
geom_point()
}
gridExtra::grid.arrange(grobs = tmp_list, nrow = 4)
【问题讨论】: