Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
验证R中的字体可用性_R_Ggtext - Fatal编程技术网

验证R中的字体可用性

验证R中的字体可用性,r,ggtext,R,Ggtext,我的操作系统上安装了字体,因此此代码运行良好: library(tidyverse) library(extrafont) iris %>% ggplot(aes(Sepal.Length,Sepal.Width, color = Species)) + geom_point(size = 2) + theme( text = element_text(family = "Metropolis") ) 让我们强制一个错误注释,我写的是metropolis,而不是metropo

我的操作系统上安装了字体,因此此代码运行良好:

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")
)
这给了我一个错误,这是正常的,因为字体大都市不存在

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
有没有一种方法可以让我在R中验证是否安装了某种字体?提前感谢。

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

library(extrafont)

"metropolis" %in% fonts()

[1] FALSE
您已经在使用extrafont软件包,因此可以使用字体查看已注册的字体。要检查特定字体是否可用,可以执行以下操作:

library(extrafont)

"metropolis" %in% fonts()

[1] FALSE

当我在%fontsit中尝试Metropolis%时,它给了我FALSE。我做错了什么吗?其他字体在可用之前需要在font_import中注册。请参阅了解fontsonly显示ttf字体。现在它起作用了。谢谢。当我在%fontsit中尝试Metropolis%时,它给了我错误的答案。我做错了什么吗?其他字体在可用之前需要在font_import中注册。请参阅了解fontsonly显示ttf字体。现在它起作用了。非常感谢。