highcharts 如何使用R更改hcaes组顺序?

9cbw7uwe  于 2023-01-13  发布在  Highcharts
关注(0)|答案(1)|浏览(145)

我正在使用Highcharts做一个柱形图,我试图改变组出现的顺序。
这是我的数据表:

这是我的代码和图表

hchart(data,type = "column", hcaes(x = DATA , y = VALUE, group = TIPO )) %>%
        hc_xAxis(title = NULL) %>%
        hc_yAxis(title = "undefined") %>%
        hc_exporting(enabled = TRUE) %>%
        hc_colors(c("#336600","#990000","#006666"))

我想提出的每一年,首先在,然后出,最后净。(基本上需要改变净与出)

rryofs0p

rryofs0p1#

以下是 * Yacine Hajji * 的评论。
数据:

data <- structure(list(Anos = c("2021", "2022", "2021", "2022", "2021", "2022"), 
                       Value = c(12539517L, 5418597L, 3827159L, 4457460L, 8712360L, 961152L),
                       Tipo = c("IN", "IN", "OUT", "OUT", "NET", "NET")), 
                  row.names = c(NA, -6L),
                  class = c("data.table", "data.frame"))

修改上游Tipo层:

data$Tipo <- factor(data$Tipo, levels = c("IN", "OUT", "NET"))

情节:

hchart(data,type = "column", hcaes(x = Anos , y = Value, group = Tipo )) %>%
  hc_xAxis(title = NULL) %>%
  hc_yAxis(title = "undefined") %>%
  hc_exporting(enabled = TRUE) %>%
  hc_colors(c("#336600","#990000","#006666"))

相关问题