是否有不覆盖现有文件的选项?也许它可以自动将它们保存为:file_name.png,file_name (2).png,file_name (3).png,就像Windows处理同名文件一样。
示例代码:
library(ggplot2)
dat = data.frame(x = 1:5, y = 1:5)
for (i in 1:3){
p1 = ggplot(dat, aes(x = x, y = y)) +
geom_point()
ggsave('p1.png', p1, width = 10, height = 8, dpi = 72,
overwrite = F)
}发布于 2016-01-18 14:16:49
使用paste函数创建基于i的唯一名称,即:
library(ggplot2)
dat = data.frame(x = 1:5, y = 1:5)
for (i in 1:3){
p1 = ggplot(dat, aes(x = x, y = y)) +
geom_point()
ggsave(paste0("p",i,".png"), p1, width = 10, height = 8, dpi = 72)
}来自Roland的评论:
ggsave(sprintf("p%d.png", i), p1, width = 10, height = 8, dpi = 72)https://stackoverflow.com/questions/34848137
复制相似问题