Change default ggplot font (not via theme)

Hi there,

Do you know how can I change the default font used for all text (title, caption, xytitle, xylabel, etc) in ggplot? I have a script plotting different types of figures using ggplot via different utility plot fuctions. I know I can specify font in the theme(), but I will have to change it in every plot function. Is there a way to specify the font globally at the begninging of the script and it will be applied to all ggplot?

Thanks a lot.

I've used quartzFonts():

quartzFonts(
  serif = quartzFont(
    c(
      "Times-Roman",
      "Times-Bold",
      "Times-Italic",
      "Times-BoldItalic"
    )),
  sans = quartzFont(
    c(
      "Helvetica-BoldOblique",
      "Helvetica-BoldOblique",
      "Helvetica-BoldOblique",
      "Helvetica-BoldOblique"
    )
  ),
  mono = quartzFont(
    c("Courier",
      "Courier-Bold",
      "Courier-Oblique",
      "Courier-BoldOblique"
    )
  )
)

ggplot()+
  annotate("text", x = 0, y = 0, label = "Hello!", family = "mono", fontface = "italic", size = 20)

1 Like

Thanks a lot @mduvekot. This doesn’t answer my question as I will still have to assign family in the theme.

You can set your default theme to use a specific font choice, so that every plot you make uses it, even without specifying the font. See ?theme_set() and related functions.

1 Like

No you don’t. The sans will be the default.

1 Like

This topic was automatically closed 7 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.