How can I save a list of ggplot with unique file names?

412 Views Asked by At

That's my current code for saving a list of different ggplots: The problem is that it saves all the different plotnames (raphael_2021_022.png and raphael_2021_023.png - which I want!) but every unique png file contains always the same ggplot (raphael_2021_023.png) even though it has a different name

names(barplots_emmeans) <- 
  sub("\\.xlsx$", 
      ".png", 
      names(raphael_calc_sum))
> barplots_emmeans
$raphael_2021_022.png
$raphael_2021_023.png

lapply(names(barplots_emmeans), 
       function(nm) barplots_emmeans[[nm]] + 
         ggsave(filename = file.path("C:/Users/Raphael/Desktop/barplot_emmeans/", 
                                     nm )))

How can I fix that?

0

There are 0 best solutions below