knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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.
Let's get started by loading some packages and making some simple data to use throughout the post.
library(sunburstR) packageVersion("sunburstR")
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)
d3r
will help us build our hierarchy.
library(d3r) tree <- d3_nest(dat, value_cols = "size") tree
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) )
d2b
SunburstKevin 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 )
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.
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.
Feedback and ideas led to these changes and improvements. Please keep them coming.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.