Home > Software engineering >  Manually reordering Bar Chart in R Highchart
Manually reordering Bar Chart in R Highchart

Time:11-25

I'm kind of new to highcharter and I'm trying to manually reorder the categories of a bar chart in but i can't seem to find an immediate solution. I tried to reorder with fct_relevel but it doesn't work

my code looks something like this:

library(highcharter)
library(tidyverse)

df <- data.frame(x= rep(c("john", "Luke", "Tom", "Sarah", "Laura", "Stacy"), each = 2), 
                 y = round(runif(12, min=0, max=100)),
                 z = rep(c(2020, 2021), each = 6)
                 )

df %>% hchart("bar", hcaes(x = x, y = y, group = z))

enter image description here

Data

set.seed(123)

df <-
  data.frame(x = rep(c(
    "john", "Luke", "Tom", "Sarah", "Laura", "Stacy"
  ), each = 2),
  y = round(runif(12, min = 0, max = 100)),
  z = rep(c(2020, 2021), 6))
  • Related