r - 在 ggplot2 中使用来自 Google 的 sysfonts
问题描述
我试图弄清楚如何使用sysfonts
包(或其他方法)将 Google 字体添加到 ggplot2。我可以很容易地使用它们,extrafont
但是有人有工作流程可以添加它们sysfonts
吗?以下是我到目前为止的内容:
library(ggplot2)
library(extrafont)
#> Registering fonts with R
#font_import() ## takes a while to run
loadfonts(device = "win")
#> Agency FB already registered with windowsFonts().
#> Algerian already registered with windowsFonts().
...
#> Vivaldi already registered with windowsFonts().
#> Vladimir Script already registered with windowsFonts().
#> Webdings already registered with windowsFonts().
#> Wingdings already registered with windowsFonts().
#> Wingdings 2 already registered with windowsFonts().
#> Wingdings 3 already registered with windowsFonts().
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16, family="Lucida Console"))
library(sysfonts)
font_add_google('Yanone Kaffeesatz')
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16, family="Yanone Kaffeesatz"))
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in Windows font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in Windows font database
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
由reprex 包(v0.3.0)于 2020 年 2 月 28 日创建
显然第二个情节不是用谷歌字体创建的。有任何想法吗?
解决方案
推荐阅读
- python - 重命名 **kwargs 以传递给另一个方法
- c++ - C++ 命名空间断言
- python - 线程只能在 Django Channels 中启动一次
- visual-foxpro - 如何使用标题字节计算 Visual FoxPro 表中的记录数?
- java - Java中两个不同数组之间的除数
- c# - 如何创建与数据库的连接
- javascript - React/Router/MemoryRouter - 如何传递历史属性并在子组件中使用 push()?
- python - Python,Kivy - 设置按钮相对于图像大小的大小
- java - 如何从另一个孩子那里得到一个父类的孩子
- php - 无法让 password_verify 与 password_hash(PHP、MYSQL)一起使用