Skip to content

Instantly share code, notes, and snippets.

@krassowski
Last active March 17, 2022 16:43
Show Gist options
  • Save krassowski/e13e4c08b4b1e9e40e1449b6dedbc5ec to your computer and use it in GitHub Desktop.
Save krassowski/e13e4c08b4b1e9e40e1449b6dedbc5ec to your computer and use it in GitHub Desktop.
ggtext labels fontawesome
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