1

I have around 17 unique store names. I wish to write a function such that for each facet_wrap with respect to each store, it should write a plot separately and save it as jpeg. For example: The function should be able to write jpeg for each store for variable vs value . Thus there should be 17 such jpeg outputs.

 df_melt = melt(df,id = c("Store", "series"))
    names = unique(df_melt$Store)
    df = fread('Book3.csv',sep = "auto")    
    ggplot(df_melt, aes(x=variable, y = value))+
          geom_path(aes(group=series, color = series))+
          geom_point(aes(color = series))+
          coord_cartesian()+
          theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5))+
          facet_wrap(~Store,scales = "free_y")

names
 [1]  612 1074 1254 1541 1544 1710 1770 3887 4101 4149 4415 4940 6612 6646 6934 8582 8941

I hope I am able to ask my question properly. Please members help me out.

  • I'm not sure if the feature to split a facet_wrap object has been developed or implemented. There's workaround for your question though, e.g. [Save individual facet_wrap facets as separate plot objects](https://stackoverflow.com/questions/33139247/ggplot2-save-individual-facet-wrap-facets-as-separate-plot-objects). – Adam Quek Jun 01 '17 at 06:48
  • ISTR that supplying an argument to facet_wrap nrow=1, ncol=1 will makes each facet appear on a single page. You will need to use a graphics device that can accept multi=page output. I don't think jpeg fits that requirement, so consider pdf or tiff. – IRTFM Jun 01 '17 at 07:00
  • @42- wouldn't `facet_wrap(~something, nrow=1, ncol=1)` result in "Error: nrow * ncol >= n is not TRUE"? – Adam Quek Jun 01 '17 at 07:18
  • Does this answer your question? [ggplot2: Save individual facet\_wrap facets as separate plot objects](https://stackoverflow.com/questions/33139247/ggplot2-save-individual-facet-wrap-facets-as-separate-plot-objects) – Dan Chaltiel Oct 20 '20 at 13:12

0 Answers0