Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File compression options with ggplot2

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?

like image 744
derelict Avatar asked Apr 02 '15 18:04

derelict


People also ask

How do I save a ggplot plot?

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.

What is ggplot2 and how does it work?

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.

How to add ggplot code to a TIFF file?

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.

How do I make a 300 dpi ggplot in Python?

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.


1 Answers

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.

like image 87
Nova Avatar answered Oct 20 '22 15:10

Nova