Highcharter 条形图切断 x 轴标签
Highcharter bar chart cut off x axis label
我正在用 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")
您可以尝试更简单的 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"))
我正在用 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")
您可以尝试更简单的 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"))