score:1

Using split and purrr::imap you could split your data by years and loop over the resulting list to convert your data to the nested list object required by hc_drilldown. Note: It's important to make the id a numeric and to pass a unnamed list.

library(tidyverse)
library(highcharter)
library(lubridate)

series <- split(df, year(df$date)) %>% 
  purrr::imap(function(x, y) list(id = as.numeric(y), data = list_parse2(x)))
# Unname list
names(series) <- NULL

highchart() %>%
  hc_chart(type = "column") %>%
  hc_title(text = "Example Drilldown") %>%
  hc_xAxis(type = "category") %>%
  hc_legend(enabled = FALSE) %>%
  hc_plotOptions(series = list(boderWidth = 2,
                               dataLabels = list(enabled = TRUE))) %>%
  hc_add_series(data = dfDD,
                name = "Mean",
                colorByPoint = TRUE) %>%
  hc_drilldown(allowPointDrilldown = TRUE,
               series = series)

enter image description here


Related Articles