在 ggplot2 图表的分面标题中组合文本和 fontawesome 图标?

Combine text and a fontawesome icon in facet titles in a ggplot2 chart?

是否可以在 ggplot2 图表的侧面标题中插入来自 fontawesome 的图标?

我想将图标与文字结合起来:

使用新列,将 fontawesome-icon 粘贴到标签不会。还有其他方法可以实现吗?

library(ggplot2)
library(emojifont)

mpg %>% 
mutate(fa_class = paste0(fontawesome('fa-linux'), class)) %>% 
ggplot(aes(x = year, y = displ)) +
geom_point() +
facet_wrap(~ fa_class)

无法识别图标:

我找不到使用 fontawesome() 的简单修复方法,但由于您使用的是 emojifont,您可以使用 emoji() 函数,然后更改字体系列。

library(tidyverse)
library(emojifont)

mpg %>% 
  mutate(fa_class = paste(emoji("car"), class)) %>%
  ggplot(aes(x = year, y = displ)) +
  geom_point() +
  facet_wrap(~ fa_class) +
  theme(strip.text = element_text(family = "EmojiOne"))