Set the font in highcharter R plot

Viewed 1158

Is there a way to change the default fonT of a highcharter plot in R?

library("highcharter")
data(diamonds, mpg, package = "ggplot2")

hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class))
2 Answers

Directly copied from the highcharter manual:

thm <- hc_theme(colors = c('red','green','blue'),
            chart = list(backgroundColor = "#15C0DE"),
            title = list(style = list(color ='#333333',
                                      fontFamily = "Erica One")),
            subtitle = list(style = list(color ='#666666',
                                         fontFamily = "Shadows Into Light")),
            legend = list(itemStyle = list(fontFamily ='Tangerine',color ='black')
                          ,itemHoverStyle = list(color ='gray')))


hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class)) %>%
    hc_add_theme(thm)

If you want to change the theme of all text on the chart:

my_theme <- hc_theme(
      chart = list(
        backgroundColor = "#f4fcfe", 
        style = list(
          fontFamily = "Montserrat"
        )
      )
)

hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class)) %>% 
  hc_add_theme(my_theme)

enter image description here

Related