derelict
derelict

Reputation: 3906

Image 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?

Upvotes: 9

Views: 7619

Answers (3)

Nova
Nova

Reputation: 5891

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.

Upvotes: 11

Sam
Sam

Reputation: 89

I would suggest to use tiff directly, like

tiff("my_graph.tif", units="in", width=13.3, height=6.6, res=800, compression = "lzw")

my_graph <- ggplot(....)

dev.off()

Upvotes: 1

AndrewMinCH
AndrewMinCH

Reputation: 720

If you can, try saving the image as a PDF. They're really clean vector graphics (if you want to refine in something like Illustrator) and I typically see them in the 3-5 KB range.

Upvotes: 2

Related Questions