Google字体没有显示在我的图表上,只有我的系统默认设置

时间:2018-09-17 13:56:53

标签: r fonts

我正在Debian 9.3上使用RStudio。我想使用库showtext。我运行了这段代码:

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)

结果图表应该看起来像这样...

enter image description here

但是在我的计算机上,它看起来像这样...

enter image description here

1 个答案:

答案 0 :(得分:1)

sysfonts使用的showtext软件包与RStudio的图形设备之间似乎存在一些不兼容。至少我可以在RStudio中重现该问题,但在使用其他图形设备时则不能:

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")