我正在尝试将 ggplot2 图添加到列表中,以便我可以使用 ggpubr 中的 ggarrange 函数将它们组织在多个页面上。
由于有数百个图,我正在使用一个函数来生成和保存图,但我无法让它将图返回到环境或将名称写入列表。
我相当确定这是我遗漏但无法发现的简单事物。
我正在使用的绘图功能是:
histFacet.plot <- function(x, results, info, ...) {
md<- names(x) %in% c("rn","Taxa","year","rep","block","column",
"range", "entity_id")
traits <- names(x[ , !md])
for (i in traits) {
i <-ggplot(data = x, aes_string(x = i)) +
geom_histogram(colour="black", fill="white") +
#facet_grid(x$year ~ .) +
theme_bw() +
xlab(paste0(i)) +
ylab("Frequency") +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank()) +
theme(axis.text = element_text(size = 15)) +
theme(axis.title = element_text(size = 15)) +
theme(strip.text = element_text(size = 15))
#ggsave(paste0(i,"_",info,".pdf"),path=paste(results, sep=''))
plotList<- list(plotList, list(i))
print(i)
}
return(i)
}
histFacet.plot(pd,'~/Dropbox/Research_Poland_Lab/AM Panel/Figures/Hist/',
"_raw_2018")