Saving a list of graphs by their names ()

Let's say I have a list of stories that I 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 this data, marked by each of them with their corresponding names (graphs).

 lapply(plots, function(x) { ggsave(filename=paste(...,".jpeg",sep=""), plot=x) dev.off() } ) 

What would I replace "..." so that in my working directory the graphs are saved as:

 a.jpeg b.jpeg c.jpeg 
+5
r ggplot2
source share
1 answer

maybe you need to pass list names:

 lapply(names(plots), function(x)ggsave(filename=paste(x,".jpeg",sep=""), plot=plots[[x]])) 
+13
source share

All Articles