how can I make svglite render portable svgs on travis-ci?

159 Views Asked by At

Plots rendered through svglite look differently when rendered through Travis, then when rendered locally.

This happens, because my local machine (macOS in this case) aliases different (more standard?) fonts for the default R plots

gdtools::match_family("Arial")
## [1] "Arial"
gdtools::match_family("sans")
## [1] "Bitstream Vera Sans"

... than travis ci:

gdtools::match_family("Arial")
## [1] "Liberation Sans"
gdtools::match_family("sans")
## [1] "DejaVu Sans"

"Liberation Sans", in turn, is not necessarily available on all computers viewing the svg (it wasn't on mine, until I ran brew cask install font-liberation-sans).

So, while the locally-generated SVGs have pretty decent portability (~"Arial"), the TravisCI-generated (~"Liberation Sans") do not.

I'd like rock-solid portability that works on every computer with a reasonable current browser. I understand from svglite fonts vignette that I should probably use User font aliases to accomplish this, but I have not managed to get it to work, and am pretty confused about the whole font businesses.

I just want SVGs from svglite that look the same everywhere.

Here's the boilerplate index.Rmd that creates the different plots.

---
title: "index"
author: "foo"
date: "11/2/2018"
output:
  rmarkdown::html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

# `png` Device

```{r png, echo=FALSE, dev = 'png'}
plot(pressure)
```


# `svg` Device

```{r svg, echo=FALSE, dev = 'svg'}
plot(pressure)
```


# `svglite` Device

```{r svglite, echo=FALSE, dev = 'svglite'}
plot(pressure)
```

(The entire repo and travis builds is here, finished website is at http://datascience.phil.fau.de/rmdbpl/).

When rendered locally (macOS) all three plots look roughly the same:

rendered locally

When build on Travis CI, the plot rendered through svglite, viewed on a machine without "Liberation Sans" will substitute a serif fonts, which looks bad.

travis

0

There are 0 best solutions below