Skip to contents

These functions help you quickly create interactive hierarchical plots from categorical data. They expect the summary of the data created by dplyr::count() and produce either a sunburst plot (count_to_sunburst()) or a treemap plot (count_to_treemap())

Usage

count_to_sunburst(
  count_data,
  fill_by_n = FALSE,
  sort_by_n = FALSE,
  maxdepth = 2
)

count_to_treemap(count_data, fill_by_n = FALSE, sort_by_n = FALSE)

Arguments

count_data
fill_by_n

If TRUE, uses a continuous scale to fill plot by group size

sort_by_n

Examples

library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
starwars_count <- count(starwars, species, eye_color, name)

# sunburst plot
count_to_sunburst(starwars_count)
# fill by group size count_to_sunburst(starwars_count, fill_by_n = TRUE)
# treemap plot, ordered by group size count_to_treemap(starwars_count, sort_by_n = TRUE)
# display al charchaters by homeworld starwars %>% count(homeworld, name) %>% count_to_treemap(sort_by_n = TRUE)