We produce an R markdown weekly report which has a large number of small graphs. The ggplots are saved as png and then integrated in the markdown script and encoded in the html. We recently moved the scripts producing this report to a linux machine with CentOS 7 and RStudio Server Open Source. The files produced on the linux machine are 3-4 times as large (20MB to 80MB).
On investigation it seems the reason is that the PNG images are saved as indexed colour on Windows but RGB on linux. I cannot figure out a way to change the way the ggplots are saved on linux. Any tips?
A simple example:
library(ggplot2)
ggplot(mtcars, aes(mpg, hp)) + geom_point() +
geom_smooth(method = lm, se = FALSE)
ggsave("test_image.png")
Produces an 88 kb image on linux and a 37 kb image on Windows.
Running R 4.0.3 and ggplot 3.3.2 on both machines.
Update: Some more investigation on images produced by linux vs windows:
> image_read(url_windows)
# A tibble: 1 x 7
format width height colorspace matte filesize density
<chr> <int> <int> <chr> <lgl> <int> <chr>
1 PNG 600 2545 sRGB FALSE 100070 20x20
> image_read(url_linux)
# A tibble: 1 x 7
format width height colorspace matte filesize density
<chr> <int> <int> <chr> <lgl> <int> <chr>
1 PNG 1800 7635 sRGB FALSE 1046302 59x59
Images on windows are 1/3 the size and density.
So seems there is a simple way of solving this. Thanks for the feedback!