4

I changed the font of my lattice plot to LM Modern 10, which I include in a personalized theme. Is there also an option to include the font style of the legend in the theme? If not, is it possible to change the font style in the key argument?

Thanks, Mara

code example:

mytheme<-list()
mytheme$par.xlab.text$fontfamily="LM Roman 10"

my.key <- list(
  space="bottom",
  columns=3,
  lines=list(pch=c(19,1,15),  size = 7,type=c("p")),
  text = list(c("text1", "text2", "text3")))

xyplot(data=dataframe,
       d1~d2,
       par.settings=mytheme,
       key=my.key)

turbo_m
  • 61
  • 3
  • If it's not too much work, I'd suggest switching to `ggplot` to have better support moving forward https://stackoverflow.com/q/34522732/786542 – Tung Apr 11 '19 at 12:43
  • 1
    Thanks for the answer. Unfortunately I do not have any experience using ggplot, so I would prefer to stick with lattice. – turbo_m Apr 11 '19 at 13:53
  • No problem but do check out http://www.ggplot2-exts.org/gallery/ to see if you can take advantage of a wide variety of addon packages for `ggplot2` – Tung Apr 11 '19 at 14:28
  • I guess I will try ggplot. Thanks for the reply – turbo_m Apr 12 '19 at 11:58

1 Answers1

2

I think it might be done... try this:

  1. load fontset using extraFonts. In this example I am going to use Old Standard font (https://fonts.google.com/specimen/Old+Standard+TT?selection.family=Old+Standard+TT) as I can't find a true type for LM Roman.

    # do once! library(extrafont) font_import(pattern = "Old*", path = "C:/Downloads/Old_Standard_TT")

  2. Next load the font (do every time with extraFont)

    library(extrafont) loadfonts(device = "win")

  3. Change par.settings in lattice:

`

library(lattice)


dataframe <- data.frame(d1 = rnorm(100), d2 = rnorm(100))

font.settings <- list(
  font = 1,
  cex = 1,
  fontfamily = "Old Standard TT")


my.theme <- list(
  par.xlab.text = font.settings,
  par.ylab.text = font.settings,
  axis.text = font.settings,
  sub.text = font.settings,
  add.text = font.settings)

my.key <- list(
  space="bottom",
  columns=3,
  lines=list(pch=c(19,1,15),  size = 7,type=c("p")),
  text = list(c("text1", "text2", "text3")),
  fontfamily = "Old Standard TT")

xyplot(data=dataframe,
       d1~d2,
       par.settings=my.theme,
       key=my.key)




`

lattice output with fonts

https://r.789695.n4.nabble.com/color-and-fontfamily-in-lattice-td877556.html

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