0

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?

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Raphael
  • 29
  • 5
  • 4
    ggsave is saving the last displayed ggplot object. You can try redisplaying the plot with `print(barplots_emmeans[[nm]])` then calling `ggsave`. I suggest reading help at `?ggsave` – Dave2e May 08 '21 at 18:07
  • 1
    nice -worked perfectly!, – Raphael May 08 '21 at 18:14

0 Answers0