5

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

Phil
  • 7,287
  • 3
  • 36
  • 66
vevvostar
  • 135
  • 8
  • 1
    Which part exactly didn't work for R 4.1.2. What code did you run? – MrFlick Mar 01 '22 at 16:19
  • @MrFlick the code in this answer: https://stackoverflow.com/a/35989404/11578991 without changing anything. Should I update my question? – vevvostar Mar 01 '22 at 16:35
  • 1
    Same problem, I get this error: > font_import(pattern = "lmroman*") Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system. Continue? [y/n] y Scanning ttf files in /Library/Fonts/, /System/Library/Fonts, /System/Library/Fonts/Supplemental, ~/Library/Fonts/ ... Extracting .afm files from .ttf files... Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : arguments imply differing number of rows: 0, 1 – wolfsatthedoor Oct 23 '22 at 22:35

0 Answers0