【问题标题】:Combine text and a fontawesome icon in facet titles in a ggplot2 chart?在 ggplot2 图表中的构面标题中结合文本和字体图标?
【发布时间】:2019-09-21 05:17:12
【问题描述】:

是否可以在 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)

图标无法识别:

【问题讨论】:

    标签: r ggplot2 font-awesome


    【解决方案1】:

    我找不到使用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"))
    

    【讨论】:

    • 非常感谢!为什么fontawesome() 更难?最后,我想用fa-icons
    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2018-08-29
    相关资源
    最近更新 更多