/
sunburst-2-0-0.Rmd
100 lines (75 loc) · 2.91 KB
/
sunburst-2-0-0.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
title: "Sunburst 2.0.0"
author: "Kent Russell"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Sunburst 2.0.0}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---
```{r setup, include = FALSE}
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](https://github.com/timelyportfolio/sunburstR/issues/60) and [61](https://github.com/timelyportfolio/sunburstR/issues/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.
```{r}
library(sunburstR)
packageVersion("sunburstR")
```
Simple data should suffice for these examples.
```{r}
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`](https://github.com/timelyportfolio/d3r) will help us build our hierarchy.
```{r}
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.
```{r}
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` Sunburst
Kevin Warne has built an incredible sunburst in [`d2b`](https://d2bjs.com), so I just had to add it to `sunburstR`. I think Kevin's work definitely deserves a star on [Github](https://github.com/d2bjs), and with only 32, I encourage a quick detour to share the love.
```{r}
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](https://github.com/timelyportfolio/sunburstR/issues/62). 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](https://github.com/timelyportfolio/sunburstR/commit/fcb11b002456f2e522b0644d7df09a19332f7c96) shows the bug fix if anyone is interested.
## Ideas and Feedback
Feedback and ideas led to these changes and improvements. Please keep them coming.