0

I would like to specify a font for all text when making a ggplot. I found I can set the base size under ggplot's selected theme but cannot find a clear example of setting to a monospaced font such as say Courier or preferably Roboto Mono for the entire plot.

This solution looked like it should work:

Can't change fonts in ggplot/geom_text

But no joy in my attempt below

install.packages("extrafont")
library(extrafont)
loadfonts(device = "win")

require(tidyverse)

ggplot(mtcars, aes(x = mpg, y = cyl, group = carb)) +
  geom_point() +
  theme_light(base_size = 15, base_family = "Roboto Mono")
Markm0705
  • 1,340
  • 1
  • 13
  • 31
  • 1
    Have you registered your fonts? If you type ```windowsFonts()$`Roboto Mono` ``` do you get `NULL` or `Roboto Mono` returned in the console? – Allan Cameron Feb 04 '23 at 23:14
  • Yes I get NULL - will look into registering fonts ... OK just noticed how to below ... Thank you – Markm0705 Feb 05 '23 at 04:28

1 Answers1

1

Going along with @Allan Cameron 's response.

windowsFonts('Roboto Mono'=windowsFont("Roboto Mono"))
ggplot(mtcars, aes(x = mpg, y = cyl, group = carb)) +
  geom_point()  +
  theme_light(base_size = 15, base_family = windowsFonts()$`Roboto Mono`)