在highcharter R图中设置字体

时间:2019-10-17 12:06:54

标签: r r-highcharter

是否可以更改R中高图表的默认字体?

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

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

2 个答案:

答案 0 :(得分:1)

直接从highcharter手册中复制:

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)

答案 1 :(得分:0)

如果要更改图表上所有文本的主题:

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