Highcharter bar chart cut off x axis label

若如初见. 提交于 2020-03-23 08:03:49

问题


I'm doing some plot with highcharter, but have some issues with label when ploting stacked barchart whan I have only one category. When I have more than one category it works well, how can I fix that ? Thanks

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

回答1:


You could try the simpler hchart way. For my example, I use the data from highcharter page:

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)

Now mpgman1, mpgman2, mpgman3 are used to be plotted as follows:

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

that works also for the case when one group exists:

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

or even when one level exists:

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


来源:https://stackoverflow.com/questions/57474984/highcharter-bar-chart-cut-off-x-axis-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!