# Sunburst 2.0.0

#### 2021-09-19

sunburstR goes 2.0.0 with some new features and bug fixes motivated by the feedback and discussion in issues 60 and 61. I thought a vignette would be a good way to demonstrate.

## Setup and Data

Let’s get started by loading some packages and making some simple data to use throughout the post.

library(sunburstR)
packageVersion("sunburstR")
#> [1] '2.1.6'

Simple data should suffice for these examples.

library(htmltools)
library(d3r)

dat <- data.frame(
level1 = rep(c("a", "b"), each=3),
level2 = paste0(rep(c("a", "b"), each=3), 1:3),
size = c(10,5,2,3,8,6),
stringsAsFactors = FALSE
)

knitr::kable(dat)
level1 level2 size
a a1 10
a a2 5
a a3 2
b b1 3
b b2 8
b b3 6

d3r will help us build our hierarchy.

library(d3r)
tree <- d3_nest(dat, value_cols = "size")
tree
#> {"children":[{"name":"a","children":[{"name":"a1","size":10,"colname":"level2"},{"name":"a2","size":5,"colname":"level2"},{"name":"a3","size":2,"colname":"level2"}],"colname":"level1"},{"name":"b","children":[{"name":"b1","size":3,"colname":"level2"},{"name":"b2","size":8,"colname":"level2"},{"name":"b3","size":6,"colname":"level2"}],"colname":"level1"}],"name":"root"}

## legend = FALSE

Often the legend in the sunburst becomes useless with lots of nodes and multiple levels. While a hack could turn it off, I don’t like having to ask users to resort to hacks, so now the argument legend = FALSE will turn it off.

sb1 <- sunburst(tree, width="100%", height=400)
sb2 <- sunburst(
tree,
legend = FALSE,
width = "100%",
height = 400
)

# do side-by-side for comparison
div(
style="display: flex; align-items:center;",
div(style="width:50%; border:1px solid #ccc;", sb1),
div(style="width:50%; border:1px solid #ccc;", sb2)
)
Legend
Legend

## d2b Sunburst

Kevin Warne has built an incredible sunburst in d2b, so I just had to add it to sunburstR. I think Kevin’s work definitely deserves a star on Github, and with only 32, I encourage a quick detour to share the love.

sb3 <- sund2b(tree, width="100%")

div(
style="display: flex; align-items:center;",
sb3
)

## Sum Nodes

I love treemap, and I enjoy using the results from treemap in a sunburst. However, recent changes resulted in double-counted sums as discussed in this issue. This double counting happens when the tree is pre-summed. I added a sumNodes = FALSE argument to disable the auto-sum.

## Bug Fix

This is hard to see, but I discovered that the breadcrumbs were duplicated on each resize. This commit shows the bug fix if anyone is interested.

## Ideas and Feedback

Feedback and ideas led to these changes and improvements. Please keep them coming.