Save ggplot with a function

前端 未结 3 1649
北荒
北荒 2021-01-31 08:21

I would like to create a function to save plots (from ggplot).

Here is a data frame:

### creating data frame
music <- c(\"Blues\", \"Hip-         


        
3条回答
  •  北海茫月
    2021-01-31 08:29

    If you would like an image file instead of a pdf, also the following works

    ggsave(filename="myPlot.jpg", plot=last_plot())
    

    or with additional parameters, as follows.

    ggsave(filename="myPlot.jpg", plot=lastplot(),
           width = 10, height = 5, 
           units = "cm", # other options are "in", "cm", "mm" 
           dpi = 200
           )
    

    Also following file types are supported "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf".

提交回复
热议问题