I find that PNG/JPEG images in Xaringan (xaringan::moon_reader()
) html slides are visually soft and fuzzy compared to SVGs. See sample screenshots below.
In contrast, these three formats are visually comparable in standard html report (rmarkdown::html_document()
). See screenshot below.
The obvious solution was to use SVG. But, SVGs explode in size for complex figures. So, it's a bit risky to use as default in a template.
This image below for example, is 7MB as SVG while the corresponding PNG is 50kB. Having many such SVG figures can lead to the final document being hundreds of MBs in size.
Using an online tool (https://vecta.io/nano), I was able to bring the 7MB SVG down to 1.6MB (>75% reduction). Huge difference in size without obvious visual change in quality. Still far from PNG sizes.
So, some of my questions are:
Why is the PNG quality bad in xaringan? What can be done to improve it?
Are there tools/devices in R that can decrease SVG size? (simplify/flatten paths?)
Other thoughts/suggestions?
## DON'T CLICK "RUN CODE SNIPPET" AS IT RUNS AS JAVASCRIPT ## THIS IS ONLY TO COLLAPSE CODE --- title: "Image quality" output: xaringan::moon_reader --- ## dev="svg",fig.height=5,fig.width=5 ```{r,dev="svg",fig.height=4.8,fig.width=4.8} plot(1:5,1:5) ``` --- ## dev="png",fig.height=6,fig.width=6 ```{r,dev="png",fig.height=6,fig.width=6} plot(1:5,1:5) ``` --- ## dev="jpeg",fig.height=6,fig.width=6 ```{r,dev="jpeg",fig.height=6,fig.width=6} plot(1:5,1:5) ``` # R version 4.1.0 (2021-05-18) # Platform: x86_64-conda-linux-gnu (64-bit) # Running under: Ubuntu 20.04.3 LTS # # rmarkdown_2.10 # xaringan_0.22