Saving a high resolution image in R

前端 未结 2 1444
梦谈多话
梦谈多话 2021-01-30 08:23

I\'m creating a scatterplot using ggplot in R (R version 3.2.1). I want to save the graph as a tiff image in 300 DPI in order to publish it in a journal. However, my code using

相关标签:
2条回答
  • 2021-01-30 09:01

    A simpler way is

    ggplot(data=df, aes(x=xvar, y=yvar)) + 
    geom_point()
    
    ggsave(path = path, width = width, height = height, device='tiff', dpi=700)
    
    0 讨论(0)
  • 2021-01-30 09:05

    You can do the following. Add your ggplot code after the first line of code and end with dev.off().

    tiff("test.tiff", units="in", width=5, height=5, res=300)
    # insert ggplot code
    dev.off()
    

    res=300 specifies that you need a figure with a resolution of 300 dpi. The figure file named 'test.tiff' is saved in your working directory.

    Change width and height in the code above depending on the desired output.

    Note that this also works for other R plots including plot, image, and pheatmap.

    Other file formats

    In addition to TIFF, you can easily use other image file formats including JPEG, BMP, and PNG. Some of these formats require less memory for saving.

    0 讨论(0)
提交回复
热议问题