Last active
March 17, 2022 16:43
-
-
Save krassowski/e13e4c08b4b1e9e40e1449b6dedbc5ec to your computer and use it in GitHub Desktop.
ggtext labels fontawesome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtext) | |
library(ggplot2) | |
library(fontawesome) | |
fa_html = function(icon) { | |
fa_png(icon) | |
paste0("<img src='", icon, ".png' width='20'>") | |
} | |
icons_map = c( | |
setosa = 'car', | |
virginica = 'ban', | |
versicolor = 'star' | |
) | |
( | |
ggplot(iris, aes(Species, Sepal.Width, fill=Species)) | |
+ geom_boxplot() | |
+ scale_fill_discrete( | |
labels=function(label) paste0( | |
sapply(icons_map[label], fa_html), | |
'<br>', | |
label | |
) | |
) | |
+ theme(legend.text=element_markdown()) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment