我需要制作一系列单独的图表,并希望在for循环中完成。我正在使用ggplot2。如果facet选项可以将每个图表保存到单独的文件中,那就好了,但我认为它做不到。
由于图表没有保存到文件中,所以出现了一些问题。尽管生成了文件,但是文件是空的。以下是我的代码示例:
for(i in 1:15) {
pdf(paste("path/plot", i, ".pdf", sep=""), width=4, height=4)
abc <- ggplot(data[data[,3]==i,],
aes(variable, value, group=Name, color=Name)) +
geom_point(alpha=.6, size=3)+geom_line() +
theme(legend.position="none", axis.text.x = element_text(angle = -330)) +
geom_text(aes(label=Name),hjust=0, vjust=0, size=2.5) +
ggtitle("Title")
abc
dev.off()
}
如何将这些图保存到文件中?
请注意,如果I是一个数值并且我在for循环内运行代码,则一切正常。
print(abc)
吗? - Mehdi Nellen