-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Support FontAwesome Icons for Markers #60
Comments
A few comments here.
|
Did a little more investigating. Here's several options I've explored: ggtext{ggtext}'s library(tidyverse)
library(showtext)
library(ggtext)
# Import fonts
font_add(family = "fa-reg",
regular = "inst/fontawesome/webfonts/fa-regular-400.ttf")
font_add('fa-brands', 'inst/fontawesome/webfonts/fa-brands-400.ttf')
font_add('fa-solid', 'inst/fontawesome/webfonts/fa-solid-900.ttf')
# Important step to enable showtext font rendering!
showtext_auto()
tibble(x = runif(25), y = runif(25)) %>%
ggplot(aes(x, y, label = "<span style='font-family:fa-solid;'></span>")) +
geom_richtext(size = 12, label.colour = NA, fill = NA, col = 'dodgerblue4',) +
theme_minimal() ggsvg / rsvgUnfortunately {ggsvg} is not on CRAN, but it is a pretty simple way to take the fontawesome the SVG outputs supplied by the actual {fontawesome} package and put them in a ggplot pretty easily, requiring no file downloads on our part: library(ggplot2)
library(rsvg)
library(ggsvg)
df <- data.frame(
text = c("Hospital", "Hotel", "School"),
icon = c(fontawesome::fa("hospital"), fontawesome::fa("hotel"), fontawesome::fa("school")),
rank = c(1, 5, 10)
)
ggplot(data = df, mapping = aes(x = rank, y = text)) +
geom_point_svg(aes(svg = icon), show.legend = FALSE) Other downsides are coloring these and having them appear well in the legend are both non trivial. emojifontExample above and as you mentioned, a little outdated but plays well with I'm partial to this solution since it works directly with I'm also opposed to this solution because while it is on CRAN it hasn't been actively worked on in 3+ years. Evolving ThoughtsI think that in the end, we can point users to any of these solutions or we can look into opening up issues with packages like {fontawesome} with Rich Iannone's group to see if there's a better way to grab their outputs and have them mesh with ggplot2. I'm worried that doing too much to get this working innately in {ggswim} is outside the scope of the package itself, at least at this early stage. I can also ask the extenders group for any thoughts. |
I think it's totally fair to use {emojifont} code as a inspiration or a starting point and reimplement what it does in {ggswim}. Of course we'll acknowledge the author! |
Ok I'll investigate a bit more, maybe open an issue to {emojifont} to see if they can update the FA version |
I'm 90% to having an implemented solution over on the fontawesome-dev branch: library(ggplot2)
library(dplyr)
devtools::load_all()
df <- cars |>
mutate(
glyph = case_when(speed > 16 ~ fontawesome("fa-car"),
.default = fontawesome("fa-bicycle")),
label = case_when(speed > 16 ~ "Fast",
.default = "Slow"),
color = case_when(speed > 16 ~ "red",
.default = "green")
) |>
tibble::tibble()
ggplot() +
geom_swim_marker(
data = df,
aes(x = speed, y = dist, marker = label),
size = 5, family = "fa"
) +
scale_marker_discrete(glyphs = df$glyph,
colours = df$color,
limits = df$label) The issue I'm running into is that once the font is loaded from our new setup, it masks or interferes with AGG device rendering for emojis, causing them to go back to appearing as empty rectangles or other aberrant text: df <- cars |>
mutate(
glyph = case_when(speed > 16 ~ "✅",
.default = "❌ "),
label = case_when(speed > 16 ~ "Fast",
.default = "Slow"),
color = case_when(speed > 16 ~ "red",
.default = "green")
) |>
tibble::tibble()
ggplot() +
geom_swim_marker(
data = df,
aes(x = speed, y = dist, marker = label),
size = 5, family = "fa"
) +
scale_marker_discrete(glyphs = df$glyph,
colours = df$color,
limits = df$label) This is also the case when you simply call |
Have found the real issue to be here: Trying to see if I can hack and identify what's going on. |
Solved! Did away with df <- cars |>
mutate(
glyph = case_when(speed > 16 ~ "✅",
.default = fontawesome("fa-car")),
label = case_when(speed > 16 ~ "Fast",
.default = "Slow"),
color = case_when(speed > 16 ~ "red",
.default = "green")
) |>
tibble::tibble()
ggplot() +
geom_swim_marker(
data = df,
aes(x = speed, y = dist, marker = label),
size = 5, family = "FontAwesome"
) +
scale_marker_discrete(glyphs = df$glyph,
colours = df$color,
limits = df$label) |
Cool! |
Feature Request Description
It would be nice to also allow for fontawesome icons in addition to shapes/glyphs and emojis. the
fontawesome
package does not currently seem capable of doing this, butemojifont
might.Additional Context
Here is an example output using
geom_text
and theemojifont
package:Checklist
The text was updated successfully, but these errors were encountered: