title: How to drill down to the third hierarchy using higherchart package in R?
body: <p>I want to create a drill down chart. For that, I created a hierarchy. I can drill down to the second level but unfortunately, I cannot drill down to the third level. Following is the working code for the two level drill down.</p>
  <pre><code>library(rio)
  library(dplyr)
  library(purrr)
  library(highcharter)
  library(scales)
  library(stringr)
  
      #My Raw data
      Test &lt;- data.frame(Group = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, 
                               &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;),
                     Group_Two = c(&quot;AA&quot;, &quot;AAA&quot;, &quot;AA&quot;, &quot;AAA&quot;, &quot;AAA&quot;, &quot;AA&quot;, 
                                   &quot;AA&quot;, &quot;AAA&quot;, &quot;BB&quot;, &quot;BBB&quot;, &quot;BB&quot;, &quot;BBB&quot;, 
                                   &quot;BB&quot;, &quot;BBB&quot;, &quot;BB&quot;, &quot;BBB&quot;),
                     Group_Three = c(&quot;AJX&quot;, &quot;ABX&quot;, &quot;AJX&quot;, &quot;ABX&quot;, &quot;APX&quot;, &quot;ANX&quot;, 
                                     &quot;ANX&quot;, &quot;APX&quot;, &quot;BJX&quot;, &quot;BBX&quot;, &quot;BJX&quot;, &quot;BBX&quot;, 
                                     &quot;BPX&quot;, &quot;BNX&quot;, &quot;BPX&quot;, &quot;BNX&quot;),
                     Group_Four = c(&quot;TH&quot;, &quot;TH&quot;, &quot;SW&quot;, &quot;SW&quot;, &quot;GC&quot;, &quot;PB&quot;, &quot;JB&quot;, 
                                    &quot;NX&quot;, &quot;TH&quot;, &quot;TH&quot;, &quot;SW&quot;, &quot;SW&quot;, &quot;GC&quot;, &quot;PB&quot;, 
                                    &quot;JB&quot;, &quot;NX&quot;),
                     Value = c(5293, 78225, 33235, 56022, 13056, 6160, 44067, 75529, 
                               95679, 98172, 27159, 77475, 37838, 25897, 88400, 28484))
  
  ######################First Hierarchy##########################
  First_test_df &lt;- aggregate(Test$Value~Test$Group, Test, FUN = sum)
  colnames(First_test_df) &lt;- c(&quot;Hierarchy_One&quot;, &quot;price&quot;)
  
  latest_First_Hierarchy &lt;- First_test_df %&gt;%
            select(c(Group = Hierarchy_One, Value = price)) %&gt;%
            arrange(desc(Value))
  
  ######################Second Hierarchy##########################
  Second_Test &lt;- Test[,c(&quot;Group&quot;, &quot;Group_Two&quot;, &quot;Value&quot;)]
  
  Second_test_df &lt;- aggregate(Second_Test$Value~ Second_Test$Group + Second_Test$Group_Two, Test, FUN = sum)
  colnames(Second_test_df) &lt;- c(&quot;Hierarchy_One&quot;, &quot;Hierarchy_Two&quot;, &quot;price&quot;)
  
  latest_Second_Hierarchy &lt;- Second_test_df %&gt;%
    select(c(Group = Hierarchy_One, Group_Two = Hierarchy_Two, Value = price)) %&gt;%
    filter(Group %in% latest_First_Hierarchy$Group) %&gt;%
    arrange(Group, desc(Value)) %&gt;%
    group_by(Group) %&gt;%
    ungroup() %&gt;%
    arrange(Group, desc(Value))
  
  ############Drill down to the second level#############
  Test_drilldown &lt;-latest_Second_Hierarchy %&gt;%
    group_nest(Group)%&gt;%
    mutate(
      id = Group,
      type = &quot;column&quot;,
      data = map(data, mutate, name = Group_Two, y = Value, drilldown = Group_Two),
      data = map(data, list_parse)
    )
  
  ###################Chart##################
  mygraph &lt;- hchart(
    latest_First_Hierarchy,
    &quot;column&quot;,
    hcaes(x = Group, y = Value, name = Group, drilldown = Group),
    name = &quot;Median Home Values&quot;,
    colorByPoint = TRUE
  )
  
  ###############Chart with the first drill down#############
  mygraph &lt;- mygraph %&gt;% 
    hc_drilldown(
      allowPointDrilldown = TRUE,
      series = list_parse(Test_drilldown)
    )
  
  mygraph
  </code></pre>
  <p>The above code allows me to drill down to the second level. Unfortunately, with the following code the chart does not drill down to the third level:</p>
  <pre><code>Test &lt;- data.frame(Group = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, 
                               &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;),
                     Group_Two = c(&quot;AA&quot;, &quot;AAA&quot;, &quot;AA&quot;, &quot;AAA&quot;, &quot;AAA&quot;, &quot;AA&quot;, 
                                   &quot;AA&quot;, &quot;AAA&quot;, &quot;BB&quot;, &quot;BBB&quot;, &quot;BB&quot;, &quot;BBB&quot;, 
                                   &quot;BB&quot;, &quot;BBB&quot;, &quot;BB&quot;, &quot;BBB&quot;),
                     Group_Three = c(&quot;AJX&quot;, &quot;ABX&quot;, &quot;AJX&quot;, &quot;ABX&quot;, &quot;APX&quot;, &quot;ANX&quot;, 
                                     &quot;ANX&quot;, &quot;APX&quot;, &quot;BJX&quot;, &quot;BBX&quot;, &quot;BJX&quot;, &quot;BBX&quot;, 
                                     &quot;BPX&quot;, &quot;BNX&quot;, &quot;BPX&quot;, &quot;BNX&quot;),
                     Group_Four = c(&quot;TH&quot;, &quot;TH&quot;, &quot;SW&quot;, &quot;SW&quot;, &quot;GC&quot;, &quot;PB&quot;, &quot;JB&quot;, 
                                    &quot;NX&quot;, &quot;TH&quot;, &quot;TH&quot;, &quot;SW&quot;, &quot;SW&quot;, &quot;GC&quot;, &quot;PB&quot;, 
                                    &quot;JB&quot;, &quot;NX&quot;),
                     Value = c(5293, 78225, 33235, 56022, 13056, 6160, 44067, 75529, 
                               95679, 98172, 27159, 77475, 37838, 25897, 88400, 28484))
  
  ######################First Hierarchy##########################
  First_test_df &lt;- aggregate(Test$Value~Test$Group, Test, FUN = sum)
  colnames(First_test_df) &lt;- c(&quot;Hierarchy_One&quot;, &quot;price&quot;)
  
  latest_First_Hierarchy &lt;- First_test_df %&gt;%
        select(c(Group = Hierarchy_One, Value = price)) %&gt;%
        arrange(desc(Value))
  
  ######################Second Hierarchy##########################
  Second_Test &lt;- Test[,c(&quot;Group&quot;, &quot;Group_Two&quot;, &quot;Value&quot;)]
  
  Second_test_df &lt;- aggregate(Second_Test$Value~ Second_Test$Group + Second_Test$Group_Two, Test, FUN = sum)
  colnames(Second_test_df) &lt;- c(&quot;Hierarchy_One&quot;, &quot;Hierarchy_Two&quot;, &quot;price&quot;)
  
  latest_Second_Hierarchy &lt;- Second_test_df %&gt;%
        select(c(Group = Hierarchy_One, Group_Two = Hierarchy_Two, Value = price)) %&gt;%
        filter(Group %in% latest_First_Hierarchy$Group) %&gt;%
        arrange(Group, desc(Value)) %&gt;%
        group_by(Group) %&gt;%
        ungroup() %&gt;%
        arrange(Group, desc(Value))
  
  ####################Third Hierarchy###############################
  Third_Test &lt;- Test[,c(&quot;Group&quot;, &quot;Group_Two&quot;, &quot;Group_Three&quot;, &quot;Value&quot;)]
  
  Third_test_df &lt;- aggregate(Third_Test$Value~ Third_Test$Group + Third_Test$Group_Two + Third_Test$Group_Three, Test, FUN = sum)
  colnames(Third_test_df) &lt;- c(&quot;Hierarchy_One&quot;, &quot;Hierarchy_Two&quot;, &quot;Hierarchy_Three&quot;, &quot;price&quot;)
  
  latest_Third_Hierarchy &lt;- Third_test_df %&gt;%
    select(c(Group_Two = Hierarchy_Two, Group_Three = Hierarchy_Three, Value = price)) %&gt;%
    filter(Group_Two %in% latest_Second_Hierarchy$Group_Two) %&gt;%
    arrange(Group_Two, desc(Value)) %&gt;%
    group_by(Group_Two) %&gt;%
    ungroup() %&gt;%
    arrange(Group_Two, desc(Value))
  
  
  Test_drilldown &lt;-latest_Second_Hierarchy %&gt;%
    group_nest(Group)%&gt;%
    mutate(
      id = Group,
      type = &quot;column&quot;,
      data = map(data, mutate, name = Group_Two, y = Value, drilldown = Group_Two),
      data = map(data, list_parse)
    )
  
  Test_drilldown_Two &lt;-latest_Third_Hierarchy %&gt;%
    group_nest(Group_Two)%&gt;%
    mutate(
      id = Group_Two,
      type = &quot;column&quot;,
      data = map(data, mutate, name = Group_Three, y = Value, drilldown = Group_Three),
      data = map(data, list_parse)
    )
  
  mygraph &lt;- hchart(
    latest_First_Hierarchy,
    &quot;column&quot;,
    hcaes(x = Group, y = Value, name = Group, drilldown = Group),
    name = &quot;Median Home Values&quot;,
    colorByPoint = TRUE
  )
  
  mygraph &lt;- mygraph %&gt;% 
    hc_drilldown(
      allowPointDrilldown = TRUE,
      series = list(list_parse(Test_drilldown), list_parse(Test_drilldown_Two))
    )
  
  mygraph
  </code></pre>
  <p>I found that the question similar to this has been asked before (link: <a href="https://stackoverflow.com/questions/38192825/how-to-make-3-levels-drilldown-plot-in-r-highcharter-possible-other-packages">How to make 3 levels drilldown plot in R highcharter (possible other packages)</a>) but I do not want to type long list of series in hc_drilldown function.</p>