1

我的操作系统上安装了字体,所以这段代码运行良好:

library(tidyverse)
library(extrafont)
iris %>% ggplot(aes(Sepal.Length,Sepal.Width, color = Species)) + 
  geom_point(size = 2) + 
theme(
  text = element_text(family = "Metropolis")
)

让我们强制一个错误(注意我写的是“metropolis”,而不是“Metropolis”):

iris %>% ggplot(aes(Sepal.Length,Sepal.Width, color = Species)) + 
  geom_point(size = 2) + 
theme(
  text = element_text(family = "metropolis")
)

这给了我一个错误,这没关系,因为字体“metropolis”不存在。

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found

有没有一种方法可以让我在 R 中验证是否安装了某些字体?先感谢您。

4

1 回答 1

3

您已经在使用该extrafont软件包,因此您可以使用它fonts()来查看已注册的字体。要检查特定字体是否可用,您可以执行以下操作:

library(extrafont)

"metropolis" %in% fonts()

[1] FALSE
于 2020-06-14T01:17:28.177 回答