ggiraph y-axis alignment issue when changing fonts

41 Views Asked by At

I'm using ggiraph to plot my ggplot object in my shiny dashboard that I deploy on shinyapps.io. My dashboard works well locally, but the font change that happens as a result of deploying on shinyapps.io results in y-axis alignment problem. At first I thought the problem is using hjust = 1 in my dashboard, but the example below is on my own computer, without using dashboard, only with font changes. I'm using the same example as ggiraph book - Chapter 3:

font_family_exists("Open Sans")
[1] TRUE

library(gdtools)
register_gfont("Open Sans")
[1] TRUE

addGFontHtmlDependency(family = "Open Sans")


dat <- mtcars
dat$carname <- row.names(dat)

gg <- ggplot(dat, aes(drat, carname)) + 
  geom_point() + 
  theme_minimal(base_family = "sans")

validated_fonts(list(sans = "Open Sans"))

$sans
[1] "Open Sans"

$serif
[1] "Times New Roman"

$mono
[1] "Courier New"

$symbol
[1] "Symbol"

Running ggiraph on the object itself works perfectly:

girafe(ggobj = gg)

image

But adding the font changes the alignment:

girafe(ggobj = gg, fonts = list(sans = "Open Sans"))

image

I'm using R 4.3.2, and ggiraph 0.8.7.

Just wondering why the labels get messed up as soon as the font changes, and whether there is any way to keep the fonts the same when a dashboard is employed on shinyapps.io.

Thanks!

0

There are 0 best solutions below