Skip to contents

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,045 × 4
#>    patient_id start      end        state    
#>         <int> <date>     <date>     <list>   
#>  1          1 2010-04-01 2010-06-30 <chr [1]>
#>  2          1 2010-08-04 2010-09-12 <chr [1]>
#>  3          1 2010-09-13 2010-11-02 <chr [2]>
#>  4          1 2010-11-03 2010-12-12 <chr [1]>
#>  5          1 2010-12-21 2011-02-19 <chr [1]>
#>  6          2 2010-02-11 2010-02-21 <chr [1]>
#>  7          2 2010-02-22 2010-03-13 <chr [2]>
#>  8          2 2010-03-14 2010-04-23 <chr [1]>
#>  9          3 2010-04-07 2010-07-06 <chr [1]>
#> 10          3 2010-10-09 2011-02-02 <chr [1]>
#> # ℹ 58,035 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)