Search code examples
rr-highcharter

Set the font in highcharter R plot


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))

Solution

  • 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)