1

I´m doing a column graph using Highcharts and I´m trying to change the order of group appearance.

This is my data.table:

enter image description here

and this is my code and graph:

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

enter image description here

I want to present for each year, first IN, then OUT and finally NET. (basically need to change Net with Out)

  • 2
    Have you tried to change upstream the `TIPO` levels order before launching your `hchart` https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame – Yacine Hajji Nov 24 '22 at 15:21

1 Answers1

0

Following Yacine Hajji comment.

Data:

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

Changing upstream the Tipo levels:

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

Plot:

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

enter image description here