Skip to contents

Creates a dataset prepared as input to the draw_sunburst_plot function.

Usage

get_sunplot_dataset(.dat, ..., .count_var)

Arguments

.dat

The data frame or a tibble with the variables and the values for the plot. See the example for the input dataset structure.

...

Variables in .dat that matches the order of the circles in the sunburst plot (innermost to outermost).

.count_var

The variable with the values to decide the sizes of the circles.

Value

A tibble to provide as input to the draw_sunburst_plot function. See details for the list of variables.

Details

The returned dataset includes the following columns.

  • .name: Label of the segment.

  • .level: Level of the sunburst plot. Level 1 is the innermost level.

  • .fill: Value for the fill variable. This is not the final colour in the plot, but the same value will have the same colour for all levels.

  • .box_min & .box_max: Minimum and maximum bounds for the segment.

  • .alpha: The transparency for that level.

  • .angle: The angle of the text label.

Examples

in_dat <- tibble::tibble(
level1_var = c(
rep("l1 A", times = 3),
rep("l1 B", times = 4)
),
level2_var = c(
"l2 A", "l2 A", "l2 B", 
"l2 C", "l2 C", "l2 D", "l2 D"
),
level3_var = c(
"l3 A", "l3 B", "l3 C", 
"l3 D", "l3 E", "l3 F", "l3 G"
),
values_var = c(
123, 456, 798, 
987, 654, 321, 159
)
)

in_dat
#> # A tibble: 7 × 4
#>   level1_var level2_var level3_var values_var
#>   <chr>      <chr>      <chr>           <dbl>
#> 1 l1 A       l2 A       l3 A              123
#> 2 l1 A       l2 A       l3 B              456
#> 3 l1 A       l2 B       l3 C              798
#> 4 l1 B       l2 C       l3 D              987
#> 5 l1 B       l2 C       l3 E              654
#> 6 l1 B       l2 D       l3 F              321
#> 7 l1 B       l2 D       l3 G              159


get_sunplot_dataset(
.dat = in_dat,
level1_var, level2_var, level3_var,
.count_var = values_var
)
#> # A tibble: 14 × 7
#>    .name .level .fill .box_min .box_max .alpha .angle
#>    <chr>  <int> <chr>    <dbl>    <dbl>  <dbl>  <dbl>
#>  1 NA         0 NA      0        1       0     -90   
#>  2 l1 A       1 l1 A    0        0.394   1      19.1 
#>  3 l1 B       1 l1 B    0.394    1       1      19.1 
#>  4 l2 A       2 l1 A    0        0.166   0.75   60.2 
#>  5 l2 B       2 l1 A    0.166    0.394   0.75  -10.7 
#>  6 l2 C       2 l1 B    0.394    0.863   0.75   43.8 
#>  7 l2 D       2 l1 B    0.863    1       0.75  -65.3 
#>  8 l3 A       3 l1 A    0        0.0352  0.667  83.7 
#>  9 l3 B       3 l1 A    0.0352   0.166   0.667  53.9 
#> 10 l3 C       3 l1 A    0.166    0.394   0.667 -10.7 
#> 11 l3 D       3 l1 B    0.394    0.676   0.667  77.5 
#> 12 l3 E       3 l1 B    0.676    0.863   0.667  -6.95
#> 13 l3 F       3 l1 B    0.863    0.955   0.667 -57.1 
#> 14 l3 G       3 l1 B    0.955    1       0.667 -81.8