I would like to have the title and axis legend in LM Roman 10 in my R plots, to better integrate them in my LateX text.
I have already tried this solution, but in R 4.1.2 does not work.
The code is the following (citing the answer to the previous question)
# Run once
install.packages("extrafont")
library(extrafont)
# Install **TTF** Latin Modern Roman fonts from www.fontsquirrel.com/fonts/latin-modern-roman
# Import the newly installed LModern fonts, change the pattern according to the
# filename of the lmodern ttf files in your fonts folder
font_import(pattern = "lmroman*")
# Run each time
library(extrafont)
loadfonts(device = "win") # this line only in Windows
par(family = "LM Roman 10")
hist(c(1,2,3,4,5), xlab = "Some data", main = "A title")
I have tried both on Windows 10 and macOS Monterey.
I have also tried to specify the full paths of the font folder.
What I see is a plot that either has the standard R font (in Windows) or has no text at all (in macOS).