【问题标题】:Highcharter bar chart cut off x axis labelHighcharter 条形图截断 x 轴标签
【发布时间】:2019-12-19 20:20:26
【问题描述】:

我正在使用 highcharter 进行一些绘图,但是在绘制堆叠条形图时标签存在一些问题,而我只有一个类别。当我有多个类别时它运行良好,我该如何解决? 谢谢

df <- structure(list(nom_part="BOB", id_part="565626235", fact_cada_annee="2018", ok=1), 
                row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame"))

highchart() %>% 
  hc_chart(type = "column") %>% 
  hc_plotOptions(column = list(stacking = "normal")) %>%
  hc_xAxis(categories = df$fact_cada_annee) %>%
  # hc_add_series(name="Autres",
  #               data = df$autres,
  #               stack = "Assets") %>%
  # hc_add_series(name="Ko",
  #               data = df$ko,
  #               stack = "Assets") %>% 
  hc_add_series(name="Ok",
                data = df$ok,
                stack = "Assets") %>% 
  hc_title(text = "Evolution note cadastre par année")

【问题讨论】:

    标签: r r-highcharter


    【解决方案1】:

    您可以尝试更简单的hchart 方式。对于我的示例,我使用来自highcharter 页面的数据:

    data(mpg,package='ggplot2')
    mpgman1 <-mpg %>% count(class, year)
    mpgman2 <-mpg %>% count(class, year) %>% filter(class == '2seater')
    mpgman3 <-mpg %>% count(class, year) %>% filter(class =='2seater',year == 1999)
    

    现在mpgman1mpgman2mpgman3被用来绘制如下:

    hchart(mpgman1, "column", hcaes(x = class, y = n, group = year))%>%
     hc_plotOptions(column = list(stacking = "normal"))
    

    这也适用于存在一组的情况:

    hchart(mpgman2, "column", hcaes(x = class, y = n, group = year))%>%
     hc_plotOptions(column = list(stacking = "normal"))
    

    甚至当存在一层时:

     hchart(mpgman3, "column", hcaes(x = class, y = n, group = year))%>%
     hc_plotOptions(column = list(stacking = "normal"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多