File compression options with ggplot2

半世苍凉 提交于 2019-12-01 18:40:06

问题


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?


回答1:


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.




回答2:


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:


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()


来源:https://stackoverflow.com/questions/29419461/file-compression-options-with-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!