Overview

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).

Basic Sunburst

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,214 × 4
#>    patient_id start      end        state    
#>         <int> <date>     <date>     <list>   
#>  1          1 2010-01-10 2010-03-11 <chr [1]>
#>  2          1 2010-03-13 2010-04-12 <chr [1]>
#>  3          1 2010-07-07 2010-09-05 <chr [1]>
#>  4          1 2010-09-19 2010-09-25 <chr [1]>
#>  5          1 2010-09-26 2010-11-18 <chr [2]>
#>  6          1 2010-11-19 2010-12-25 <chr [1]>
#>  7          2 2010-01-08 2010-02-02 <chr [1]>
#>  8          2 2010-02-03 2010-02-07 <chr [2]>
#>  9          2 2010-02-08 2010-02-21 <chr [1]>
#> 10          2 2010-02-22 2010-05-04 <chr [2]>
#> # … with 58,204 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)