I want to draw an interactive html plot with ggiraph
changing the font to "DejaVu Sans Condensed".
This particular font works well with the interactive tooltips of girafe
when I put it in the css,
but not as the general font for text elements in the html plot itself.
Lets try with an example. First, everything works fine with ggplot2 :
library(tidyverse)
library(ggiraph)
windowsFonts(sans = windowsFont("DejaVu Sans Condensed"))
z <- ggplot(data = iris,
mapping = aes(x = Sepal.Length, y = Petal.Width)) +
geom_point() +
ggtitle("Title with special characters ♀♂") +
xlab("Sepal.Length ♀♂") + ylab("Miles per Gallon ♀♂" ) +
theme_minimal(base_family = "sans", base_size = 18)
z
We can see that the DejaVu Sans Condensed font worked, because the male and female symbols
in the titles appear as bold as the letters.
But with girafe
, symbols appears thinner because font doesn’t work/went back to Arial :
girafe(ggobj = z, fonts = list(sans = "DejaVu Sans Condensed"))
The problem may come from the gdtools
package which ggiraph
uses to manage fonts,
because it cannot find DejaVu Sans Condensed :
gdtools::font_family_exists("DejaVu Sans Condensed")
# [1] FALSE
However, if we use gdtools::sys_fonts
, we can find DejaVu Sans Condensed, but with
an incomplete font family name :
gdtools::sys_fonts() %>% filter(str_detect(name, "DejaVuSansCondensed")) %>% select(3:5)
# A tibble: 4 x 3
# name family style
# DejaVuSansCondensed-Bold DejaVu Sans Condensed Bold
# DejaVuSansCondensed-BoldOblique DejaVu Sans Condensed Bold Oblique
# DejaVuSansCondensed-Oblique DejaVu Sans Condensed Oblique
# DejaVuSansCondensed DejaVu Sans Condensed
"DejaVu Sans Condensed" exists, but the "family" name is simply "Deja Vu Sans", and the "Condensed" part went to "style" (while on the medatada of this font in my computer, using Windows, the font family name is "DejaVu Sans Condensed").
Is it a problem with the system font detection algorithm ? Or is it a normal behavior,
and then where to specify the Condensed style to use it in ggiraph
?
Thanks,