0

I have created a function that graphs out the different performance for suppliers. I am looking to save each of these graphs using their supplier number, but I am having problems writing the code for this. Here is what I have so far.

split_supplier <- split(mtdtotalchanges, mtdtotalchanges$supplier)

my_plot <- function(dat) {
  ggplot(dat, aes(x = filldate, y = totalfill)) +
   geom_col()+
  geom_vline(xintercept = "2021-02-15", linetype=8, col = "blue", size = 1) +
      theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  xlab(label= "Fill Month") +
    labs(title = unique(dat$supplier))+
    ggsave( as.character(unique(dat$supplier))+".jpg")
}

lapply(split_supplier, my_plot)
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • You do not combine strings with `+` in R, you use `paste()`. And you don't use `+` with `ggsave`. It just runs out it's own. Try `ggsave( paste0(as.character(unique(dat$supplier)), ".jpg"))` without the preceding `+`. – MrFlick Apr 16 '21 at 19:43
  • Thanks - that worked great! – dexter1988 Apr 16 '21 at 19:54

0 Answers0