Question Details

No question body available.

Tags

css r ggplot2 ggiraph

Answers (1)

Accepted Answer Available
Accepted Answer
April 20, 2026 Score: 2 Rep: 12,864 Quality: High Completeness: 80%

girafe produces an HTML-widget. For adding custom fonts, you need to give this widget access to your font. So the usual way would be to add your font as a Google-font dependency using gdtools::gfontHtmlDependency. For this to work, the font-family needs to be available at google fonts, for example "Special Gothic Condensed One" and the font-family within your ggplot2 needs be the same "Special Gothic Condensed One".

ggiraph::girafe(
  ggobj = ggplot2::ggplot(mtcars) +
    ggplot2::geompoint(ggplot2::aes(x = wt, y = qsec, color = disp)) +
    ggplot2::labs(title = "Custom font is used here") + ggplot2::theme(plot.title = ggplot2::elementtext(family = "Special Gothic Condensed One",size = 24)
  ),
  checkfontsregistered = TRUE,
  checkfontsdependencies = TRUE,
  dependencies = list(gdtools::gfontHtmlDependency(family = "Special Gothic Condensed One"))
)

Sadly, your desired font Trade Gothic LT Std Condensed No. 18.otf is not available in Google fonts. Still it is possible to add your font by registering it to be available in CSS using @font-face. If you don't do that, font-family: 'Gothiccondensed'; in your tooltipcss will simply be ignored. Note: Above code will give a warning if I don't add the dependency, because I set checkfontsdependencies = TRUE.

full working code

library(ggplot2)
library(ggiraph)
library(htmltools)

font_name