nanxstats / ggsci

🦄 Scientific journal and sci-fi themed color palettes for ggplot2
https://nanx.me/ggsci/
GNU General Public License v3.0
661 stars 71 forks source link

Create code example that scales #16

Closed nanxstats closed 1 year ago

nanxstats commented 1 year ago

R has a check note when installed package size is > 5Mb:

  installed size is  5.1Mb
  sub-directories of 1Mb or more:
    doc    2.7Mb
    help   2.3Mb

The doc here is the vignette with the figures embedded. The help here contains the output figures from README.Rmd. Since they have roughly the same content, the limit is ~2.4Mb max for each. We should prioritize the README file figure legibility as it's also served on GitHub repo besides CRAN and the pkgdown site.

For a PNG-based solution, ragg::ragg_png() generates the minimal size PNG files. We have to keep fig.width = 10.6667 and fig.height = 3.3334. While we are reaching the lower legibility limit when keeping dpi = 72. Set fig.retina = 1.2 for vignette and set fig.retina = 2 for README. This gives us 2.3 Mb + 2.6 Mb = 4.9 Mb.

For a SVG-based solution, svglite produces the minimal size SVG files. They are super legible (vector-based) and can dramatically reduce the figure sizes. However, the current code example contains too many data points and generates ~100Kb figures per palette.

Conclusion:

  1. Switch to svglite device for both README and vignette.
  2. Create a revised code example that generates much smaller SVG outputs.
nanxstats commented 1 year ago

By switching to pngquant (lossy compression) in https://github.com/nanxstats/ggsci/commit/44a8ce1e705bf56dab8750e0da6a7c7a38f90814, I was able to achieve 30Kb per file using dpi=72 and fig.retina=2 with ragg::agg_png. The README outputs and vignette outputs are ~900Kb each now.

Package builds and checks ok even if pngquant is not installed (just with much larger built vignette size).

The only thing to remember is to have pngquant installed on the R CMD build machine when submitting to CRAN.

I'd say this solution would scale well - closing this for now.