1. 检查好{sysfonts}包是否已经安装好;
2. 在原有代码块第一行增加showtext_auto():
sysfonts::font_add_google("Alegreya Sans", "aleg")
if(require(showtext))
{
showtext_auto()
wd = setwd(tempdir())
pdf("google-fonts-ex.pdf")
showtext_begin()
par(family = "aleg")
plot(0:5,0:5, type="n")
text(1:4, 1:4, "Alegreya Sans", font=1:4, cex = 2)
showtext_end()
dev.off()
setwd(wd)
}