File compression options with ggplot2

2019-02-23 03:20发布

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?

3条回答
走好不送
2楼-- · 2019-02-23 03:49

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.

查看更多
放我归山
3楼-- · 2019-02-23 03:57

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 @SoilSciGuy), ggsave will now compress your image appropriately. Mine went from 2.98 MB to 37.6 KB.

查看更多
乱世女痞
4楼-- · 2019-02-23 04:04

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()
查看更多
登录 后发表回答