Username
Username

Reputation: 3663

Google fonts don't show on my chart, only my system default

I am using RStudio on Debian 9.3. I want to use the library showtext. I ran this code:

library(showtext)
font_add_google("Lobster", "lobster")

showtext_auto()

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)

The resulting chart is supposed to look like this...

enter image description here

But on my computer, it looks like this...

enter image description here

Upvotes: 0

Views: 81

Answers (1)

Ralf Stubner
Ralf Stubner

Reputation: 26823

There seems to be some incompatibility between the sysfonts package used by showtext and RStudio's graphics device. At least I can reproduce the issue in RStudio, but not when using a different graphics device:

library(showtext)
font_add_google("Lobster", "lobster")

showtext_auto()

plot(1, pch = 16, cex = 3)
# text in some sans-serif font
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)

x11()
plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
# run this line after looking at the graph
dev.off()

pdf(file = "test1.pdf")
plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
dev.off()
browseURL("test1.pdf")

Upvotes: 1

Related Questions