Markm0705
Markm0705

Reputation: 1440

Specify default font for entire ggplot?

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")

Upvotes: 1

Views: 231

Answers (1)

scott.pilgrim.vs.r
scott.pilgrim.vs.r

Reputation: 507

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`)

Upvotes: 2

Related Questions