首页 > 解决方案 > 为什么有些华夫饼图字形有效,而其他字形无效?

问题描述

我已经在我的本地机器上安装了fontawesome ttfs 并将它们加载到 R 中。当我使用它进行测试时,它会按预期fonts()[grep("Awesome", fonts())]返回。"FontAwesome"

我可以运行带有某些字形的华夫饼图……到目前为止,男性、女性和公文包都可以使用,但其他的不行,例如“建筑”。

知道发生了什么吗?

library(ggplot2)
library(fontawesome)
library(extrafont)
library(waffle)

# This works fine
waffle(
  c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
  use_glyph = "female", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)

# This does not work
waffle(
  c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
  use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)

标签: rfont-awesomewaffle-chart

解决方案


不确定为什么某些字形会发生这种情况,但其他字形不会,但我最近遇到了同样的问题。在这里找到了一个很好的方法:https ://www.listendata.com/2019/06/create-infographics-with-r.html

听起来您已经有了可用的字体,因此可以跳过操作方法的第一部分,并且您可能只是缺少软件包。您需要添加另外两个:echarts4r(在 CRAN 上)和 echarts4r.assets(目前仅在 github 上)

require(devtools)
devtools::install_github("JohnCoene/echarts4r.assets")
library(tidyverse)
library(waffle)
library(extrafont)
library(echarts4r.assets)
library(echarts4r)

# Works for me with all of these packages loaded
waffle(
  c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
  use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)

推荐阅读