rggplot2tifffacet

How to export an image as a TIFF file after converting the ggplot object to a grob?


I created a very similar plot following the code provided in this post (similar width facets and boxplots). How to automatically adjust the width of each facet for facet_wrap?

I want to export the image as a tiff file for a manuscript. How do I do that?

I assigned the last line of code as follows:

Figure4 = grid::grid.draw(gp)

tiff("Figure4.tiff", width = 1800, height = 800, res = dpi)
Figure4
dev.off()

But the resulting figure in my directory is a blank white space. How do I export the image as a high-quality figure?

The sample code can be found in the post linked.

Help is appreciated.


Solution

  • I would use ggsave. This seems to work for me:

    ggsave("./Figure4.tiff", plot = gp, device = "tiff")
    

    Make sure to change the path in the first argument to wherever you want the image to go, if you want to change dimensions you can just pass them as width and height arguments.