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:
- install
extrafont
package. - 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. - import fonts using
font_import()
. - load fonts using
loadfonts(device = "win")
. usedevice = "win"
parameter make preview in r studio work. - set font family graphics parameter using
par(family = "lm roman 10")
. - 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))
Comments
Post a Comment