Reputation: 1355
I try to use some fontawesome icons in a ggplot2 plot. Especially the "fa-temperature-arrow-up" would be interesting for me, but i cannot make it work. I tried the emojifont package, but no success. Can somebody point me to what i am missing?
library(tidyverse)
library(ggtext)
df <- data.frame(
x = 2,
y = 1.5,
h = 4.25,
w = 6.25,
value = c("97%"),
info = c("consensus about climate change"),
icon = c("e040") #temperature-arrow-up
) %>%
mutate(icon = glue::glue("<span style='font-family:fa-solid;'>&#x{icon};</span>"))
df %>% ggplot(aes(x, y)) +
geom_richtext(aes(label = icon),
size = 12,
label.colour = NA,
fill = NA,
col = 'dodgerblue4') +
theme_minimal() +
labs(title ="I only see an empty rectangle")
sessionInfo()
R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C LC_TIME=German_Germany.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggtext_0.1.2 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0 purrr_1.0.1 readr_2.1.4
[8] tidyr_1.3.0 tibble_3.2.0 ggplot2_3.4.1 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 pillar_1.8.1 compiler_4.2.2 tools_4.2.2 sysfonts_0.8.8 digest_0.6.31
[7] timechange_0.2.0 lifecycle_1.0.3 gtable_0.3.2 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.0
[13] rstudioapi_0.14 commonmark_1.8.1 xfun_0.37 proto_1.0.0 fastmap_1.1.1 xml2_1.3.3
[19] withr_2.5.0 showtextdb_3.0 generics_0.1.3 vctrs_0.6.0 hms_1.1.2 gridtext_0.1.5
[25] emojifont_0.5.5 grid_4.2.2 tidyselect_1.2.0 glue_1.6.2 fontawesome_0.5.0 R6_2.5.1
[31] fansi_1.0.4 farver_2.1.1 tzdb_0.3.0 magrittr_2.0.3 scales_1.2.1 htmltools_0.5.4
[37] ellipsis_0.3.2 showtext_0.9-5 colorspace_2.1-0 labeling_0.4.2 utf8_1.2.3 stringi_1.7.12
[43] munsell_0.5.0 markdown_1.5
Upvotes: 0
Views: 206
Reputation: 1355
My solution was
code
library(tidyverse)
library(ggtext)
library(fontawesome)
library(showtext)
font_add(family = 'fa-solid', regular = '{PATH_TO}/fontawesome-free-6.3.0-desktop/otfs/Font Awesome 6 Free-Solid-900.otf')
df <- data.frame(
x = 2,
y = 1.5,
h = 4.25,
w = 6.25,
value = c("97%"),
info = c("consensus about climate change"),
icon = c("e040") #temperature-arrow-up
) %>%
mutate(icon = glue::glue("<span style='font-family:fa-solid;'>&#x{icon};</span>"))
showtext_auto()
df %>% ggplot(aes(x, y)) +
geom_richtext(aes(label = icon),
size = 12,
label.colour = NA,
fill = NA,
col = 'dodgerblue4') +
theme_minimal() +
labs(title ="now it works")
Upvotes: 0