Let's say I have a list of plots that I've created.
library(ggplot2)
plots <- list()
plots$a <- ggplot(cars, aes(speed, dist)) + geom_point()
plots$b <- ggplot(cars, aes(speed)) + geom_histogram()
plots$c <- ggplot(cars, aes(dist)) + geom_histogram()
Now, I would like to save all of these, labelling each with their respective names(plots) element.
lapply(plots,
function(x) {
ggsave(filename=paste(...,".jpeg",sep=""), plot=x)
dev.off()
}
)
What would I replace "..." with such that in my working directory the plots were saved as:
a.jpeg
b.jpeg
c.jpeg
Using the results from split() function, we can create a list of plots, ggplot objects, using map() function in purrr R package. In this example, map() makes a scatter plot for each species.
Saving a plot on your disk as an image file Now if you want to save matplotlib figures as image files programmatically, then all you need is matplotlib. pyplot. savefig() function. Simply pass the desired filename (and even location) and the figure will be stored on your disk.
probably you need to pass the names of list:
lapply(names(plots),
function(x)ggsave(filename=paste(x,".jpeg",sep=""), plot=plots[[x]]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With