Incorrect fonts with RStudio Server in docker

I am running R 4.3.1 in a docker (rocker/tidyverse), with RStudio Server 2023.06.0

Having some issues getting ggplot outputs with the correct font.

I have installed google fonts and loaded them via extrafont but I do not get the same outputs as I do from my windows pc.

Using the 'Alata' font as an example, and "Alata" %in% fonts() returns TRUE across both instances.

library(tidyverse)
library(extrafont)
library(ragg)

as_tibble(mtcars, rownames = "car") %>%
  slice(1:10) %>%
  ggplot(aes(x = mpg, y = car)) +
  geom_col(alpha = 0.4) +
  geom_text(aes(x = 1, label = car), hjust = 0,
            family = "Alata") +
  theme(axis.text.y = element_blank())

ggsave("test.png", height = 12, width = 9, dpi = 300, device = agg_png)

The desired image (as I get on windows) is:

But in the plot viewer on RStudio Server I get:

And the ggsave output from RStudio Server is:

What gives? extrafont can see the correct font is installed, but it doesn't get used properly by ggplot or ggsave in my docker instance?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.