Sunbursts are similar to Sankeys in that they visualize patterns, but differ in how the patterns are calculated. In Sankeys, states are calculated at cross-sectional points in time and presented as flows through time. In sunbursts, order, irrelevant to time, is considered in calculation of the pattern. For example, a patient who is on Treatment A for one year then Treatment B for one day would have the exact same pattern as someone who is on Treatment A for one day, then transitions to Treatment B for one year (A -> B).
First, the id level data are created used
sunburst_id_data
. This is to help facilitate running on
partitions on the id-level first, before the summarizing step in
sunburst_maker
. sunburst_id_data
requires a
cohort, an ansible
style data.frame, and which “states” are
wanted. It returns a list of the resulting data.frame and the states, so
it can directly be fed into sunburst_maker
.
events <- nsSank::convert_tagged_cdf(cdf)
data <- nsSank::ansible(events)
data
#> # A tibble: 58,325 × 4
#> patient_id start end state
#> <int> <date> <date> <list>
#> 1 1 2010-04-01 2010-05-31 <chr [1]>
#> 2 1 2010-09-05 2010-09-22 <chr [1]>
#> 3 1 2010-09-23 2010-11-01 <chr [2]>
#> 4 1 2010-11-02 2010-12-04 <chr [3]>
#> 5 1 2010-12-05 2010-12-08 <chr [2]>
#> 6 1 2010-12-09 2011-01-01 <chr [3]>
#> 7 1 2011-01-02 2011-02-25 <chr [2]>
#> 8 1 2011-02-26 2011-03-09 <chr [1]>
#> 9 2 2010-04-05 2010-04-21 <chr [1]>
#> 10 2 2010-04-22 2010-05-05 <chr [2]>
#> # … with 58,315 more rows
sdata <- nsSank::sunburst_id_data(cohort, data, states = c("a", "b"))
#sdata$id_data
sunburst_list <- nsSank::sunburst_maker(cohort, sdata, max_levels = 5)
nswidgets::create_sunburst(sunburst_list$data, sunburst_list$types)