Reputation: 61
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)
Upvotes: 4
Views: 1423
Reputation: 305
I think it might be done... try this:
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")
Next load the font (do every time with extraFont)
library(extrafont)
loadfonts(device = "win")
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)
`
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?
Upvotes: 2