I'm currently using for loop to save my graphs to the working directory what ever it is. OTH, I want to add one more feature that creating the directory with the graph name and store corresponding figures to those folder. For instance if the graph name is setosa
create folder named setosa
and store setosa
graph to inside to that new directory.
There is a one relative how-to-save-plots-inside-a-folder here but no solution is clearly given.
Here is my current working code for saving graphs to working directory.
library(ggplot2)
library(dplyr)
plot_list = list() # Initialize an empty list
for (i in unique(iris$Species)) {
p = ggplot(iris[iris$Species == i, ], aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point(size = 3, aes(colour = Species))
plot_list[[i]] = p
}
for (i in unique(iris$Species)) {
file_name = paste( i, ".tiff", sep="")
tiff(file_name)
print(plot_list[[i]])
dev.off()
}