Save ggplot with a function

前端 未结 3 1656
北荒
北荒 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:41

    Following was useful for me, may be for someone else as well. One can save the last plot without explicitly referring it as well.

    ggsave("filename.pdf",  # jpg, png, eps, tex, etc.
           plot = last_plot(), # or an explicit ggplot object name,
           width = 7, height = 5, 
           units = "in", # other options c("in", "cm", "mm"), 
           dpi = 300)
    

提交回复
热议问题