How to save a plot as image on the disk?

后端 未结 11 1220
失恋的感觉
失恋的感觉 2020-11-22 10:38

I plot a simple linear regression using R. I would like to save that image as PNG or JPEG, is it possible to do it automatically? (via code)

There are two different

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 10:57

    If you use ggplot2 the preferred way of saving is to use ggsave. First you have to plot, after creating the plot you call ggsave:

    ggplot(...)
    ggsave("plot.png")
    

    The format of the image is determined by the extension you choose for the filename. Additional parameters can be passed to ggsave, notably width, height, and dpi.

提交回复
热议问题