我正在使用highcharter进行绘图,但是在绘制堆积的barchart whan时,标签存在一些问题,我只有一个类别。如果我有多个类别,则效果很好,该如何解决? 谢谢
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")
答案 0 :(得分: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)
现在使用mpgman1
,mpgman2
,mpgman3
进行如下绘制:
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"))