I'm trying to create a stacked column graph which has drilldown (using the highcharter package) on R studio

I've managed to create a stacked column graph with drilldown on RStudio, but currently I've only managed to figure out (using an online example) how to make a stacked column graph, but where every bar goes to the same drill-down secondary graph.

I'm trying to make a stacked column chart with a bar-specific drill-down element to a secondary chart (each bar/stack would go to a different drill-down graph, but each segment within each bar wouldn't have a different drill down - if that makes sense).

It currently only has 2 bars but in reality I'll want much more.

Thanks

hc <- highchart() %>%
  hc_chart(
    type = "column",
    events = list(
      drilldown = JS(
        "function(e) {
        if (!e.seriesOptions) {
        var chart = this;
        chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[1],
        name: 'Criminal attacks',
        data: [
        ['PAYE', 60],
        ['SA', 65]
        ]
        });
        chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[2],
        name: 'Avoidance',
        data: [
        ['PAYE', 4],
        ['SA', 25]
        ]
        });
        chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[3],
        name: 'FTTRC',
        data: [
        ['PAYE', 10],
        ['SA', 6]
        ]
        });
chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[4],
        name: 'Error',
        data: [
        ['PAYE', 20],
        ['SA', 20]
        ]
        });
chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[5],
        name: 'Non-payment',
        data: [
        ['PAYE', 5],
        ['SA', 10]
        ]
        });
chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[6],
        name: 'Legal interpretation',
        data: [
        ['PAYE', 0],
        ['SA', 0]
        ]
        });
chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[7],
        name: 'Hidden economy',
        data: [
        ['PAYE', 10],
        ['SA', 5]
        ]
        });
chart.addSingleSeriesAsDrilldown(e.point, {
        color: Highcharts.getOptions().colors[8],
        name: 'Evasion',
        data: [
        ['PAYE', 5],
        ['SA', 5]
        ]
        });
        chart.applyDrilldown();
        }
        }"
      )
      )
      ) %>%
  hc_title(text = "Tax Assured - Payments") %>%
  hc_xAxis(type = "category") %>%
  hc_plotOptions(series = list(stacking = "normal")) %>%
  hc_yAxis(max = 160) %>%
  hc_add_series(
    name = "Small business", 
    data = list(
      list(name = "PAYE", y = 40, drilldown = T), 
      list(name = "SA", y = 35, drilldown = T)
    )
  ) %>%
  hc_add_series(
    name = "Mid-size business",
    data = list(
      list(name = "PAYE", y = 60, drilldown = T), 
      list(name = "SA", y = 65, drilldown = T)
    )
  ) %>%
  hc_add_series(
    name = "Large business",
    data = list(
      list(name = "PAYE", y = 20, drilldown = T), 
      list(name = "SA", y = 20, drilldown = T)
    )
  ) %>%
  hc_add_series(
    name = "Individuals",
    data = list(
      list(name = "PAYE", y = 20, drilldown = T), 
      list(name = "SA", y = 20, drilldown = T)
    )
  ) %>%
  hc_add_series(
    name = "Wealthy individuals",
    data = list(
      list(name = "PAYE", y = 20, drilldown = T), 
      list(name = "SA", y = 20, drilldown = T)
    )
  ) %>%
  hc_add_series(
    name = "No segmentation",
    data = list(
      list(name = "PAYE", y = 0, drilldown = T), 
      list(name = "SA", y = 0, drilldown = T)
    )
  ) %>%
  hc_drilldown(
    series = list()
  )
hc

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.