Search code examples
rsunburst-diagram

SunburstR: how to define paths i.e. add more layers to sunburst?


I am lost in how to create the hierarchy with R's SunburstR package

sunburstR::sunburst(data=as.data.frame(iris, legendOrder=list("Species", "Sepal.Length")))

n

where the pedagocical example tries to create a hierarchy with the well-known iris dataset. The inner most layer would have 3 groups: setosa, versicolor and virginica -- and outmost layers showing the proportion of certain numeric things such as sepal length.

How to add more layers to a sunburst plot?


Solution

  • You have to specify the path with each node separated by dash such that

    iris 
    %>% mutate(path = paste(Species, Sepal.Length, Petal.Width, sep='-')) 
    %>% select(path, Petal.Length) %>% sunburst()
    

    where Petal.Length here is the value you want to visualise on the outermost layer with respect to the path starting from the innermost layer to the outermost layer

    enter image description here

    and in visually more pleasing order such that

    enter image description here

    iris 
    %>% arrange(desc(Petal.Length), desc(Sepal.Length), desc(Petal.Width)) 
    %>% mutate(path = paste(Species, Sepal.Length, Petal.Width, sep='-')) 
    %>% select(path, Petal.Length) 
    %>% sunburst(breadcrumb = list(w=200))