How can I make an R plot use the Latin Modern font family when saved as a PDF? -


if type

par(family='cm roman') 

then can plot display computer modern font. however, when try save pdf, comes blank document, unlike if take out line.

how can save correctly pdf?

also, how can use latin modern instead of computer modern?

this how did in windows:

  1. install extrafont package.
  2. install latin modern fonts, e.g. http://www.fontsquirrel.com/fonts/latin-modern-roman. watch out, need install ttf version of font, font_import() can't handle otf.
  3. import fonts using font_import().
  4. load fonts using loadfonts(device = "win"). use device = "win" parameter make preview in r studio work.
  5. set font family graphics parameter using par(family = "lm roman 10").
  6. plotting in r studio works , pdf export (see pictures below).

this full code need use:

# run once install.packages("extrafont") library(extrafont) # install **ttf** latin modern roman fonts www.fontsquirrel.com/fonts/latin-modern-roman # import newly installed lmodern fonts, change pattern according  # filename of lmodern ttf files in fonts folder font_import(pattern = "lmroman*")   # run each time library(extrafont) loadfonts(device = "win") par(family = "lm roman 10") x <- seq(1, 10, 1) y <- seq(1, 10, 1) plot(y ~ x, main="this plot uses latex font!", ylab = expression(alpha)) 

r studio preview:
r studio preview

exported pdf:
pdf export


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -