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 Query

More Query from same tag