【发布时间】:2019-05-24 07:27:22
【问题描述】:
以下代码使用 ggplot 和 grid.arrange 生成图。当我以 pdf 格式保存时,顶部和底部的注释都丢失了
library(tidyverse)
library(ggplot2)
library(gridExtra)
plots <- lapply(unique(mtcars$cyl), function(cyl) {
data <- mtcars %>% filter(cyl == cyl)
ggplot(data, aes(x=mpg, y=hp))+
geom_point(color = "blue")+
facet_wrap(.~carb)}) %>%
do.call(grid.arrange, .)
do.call(grid.arrange, c(plots,list(top="top", bottom="bottom")) )
ggsave(file="C:\\temp\\plot.pdf", plots, width = 21, height = 29.7, units = "cm", dpi = 300)
【问题讨论】:
-
我认为问题在于您将
plots传递给ggsave(),而不是do.call()的输出。 -
问题解决了!谢谢