Vector graphics

2020

If you’re using a HiDPI display, such as a MacBook equipped with a Retina display, R Markdown may render graphics that appear “fuzzy” as they are not rendered with a high enough DPI for your screen.

This can be fixed by rendering to a vector graphic (svg/pdf) rather than a rasterized graphic (png/jpeg).

The R package svglite1 Wickham et al, 2015. provides an SVG device R can use as a graphics device.

install.packages("svglite")

R Markdown can use this svg device for graphical device via a knitr option.

```{r, include = FALSE}
knitr::opts_chunk$set(dev = "svglite")
```

Then all graphics following this chunk will be rendered as svgs.

library(tidyverse)
library(wplot)

iris %>%
    ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
        geom_point() +
        theme_wc()