rfontsggbiplot

Font change in ggplot not working on biplot label names


I have stumbled upon a problem, where I can change all the text in a biplot image to the another font, with the exception of labels.

A simple example of the problem is seen below, with label text clearly differing:

Code that I used is also attached. I cannot find the solution to this issue, hopefully someone can help.

p <- fviz_pca(fit, geom = c("point"), 
              repel = TRUE, label = "var", 
              habillage = IOSDV1$Fertilisation, 
              addEllipses = TRUE, ellipse.type="confidence", 
              palette = "npg", labelsize = 5, pointsize = 3, 
              col.ind = "black", col.var = "black", arrowsize = 0.6) + 
  theme_bw(base_family = "Palatino Linotype") + 
  theme(text = element_text(family = "Palatino Linotype", size = 14)) + 
  labs(title = "")

ggsave(filename = "ggplot_garamond.png", dpi = 600, type = "cairo")

Solution

  • Answer

    You have to add the font.family argument to fviz_pca:

    fviz_pca(fit, geom = c("point"), 
             repel = TRUE, label = "var", 
             habillage = IOSDV1$Fertilisation, 
             addEllipses = TRUE, ellipse.type="confidence", 
             palette = "npg", labelsize = 5, pointsize = 3, 
             col.ind = "black", col.var = "black", arrowsize = 0.6,
             font.family = "Palatino Linotype")
    

    Rationale

    Internally, fviz_pca calls fviz, which in turn calls ggpubr::ggscatter. In this function, you can specify the font family with the font.family argument.