Is it possible to compress the file size of a figure using ggsave
? I have tried using the compression = "lzw"
argument, but the file size remains the same. (Using R studio .98.501 OS-X Yosemite)
My code:
ggsave("Figure1.tiff", width = 14, height = 8, dpi=600, compression = "lzw")
Is it possible to add a compression argument with ggsave?
Save a ggplot (or other grid object) with sensible defaults. ggsave() is a convenient function for saving a plot. It defaults to saving the last plot that you displayed, using the size of the current graphics device.
ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics . You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.
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.
Add your ggplot code after the first line of code and end with 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.
UPDATE:
I just tried this option with ggplot2 2.2.1. If you save using the file ending ".tiff"
, and specify compression = "lzw"
, (exactly as written by @Derelict), ggsave will now compress your image appropriately. Mine went from 2.98 MB to 37.6 KB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With