sunburstTreemap | R Documentation |
Create sunburst treemaps where variables are encoded by size of circular sectors.
sunburstTreemap(
data,
levels,
fun = sum,
sort = TRUE,
filter = 0,
cell_size = NULL,
custom_color = NULL,
diameter_inner = 0.3,
diameter_outer = 0.8,
verbose = FALSE
)
data |
(data.frame) A data.frame with one column for each hierarchical level |
levels |
(character) Character vector indicating the column names to be used. The order of names must correspond to the hierarchical levels, going from broad to fine |
fun |
(function) Function to be used to aggregate cell sizes of parental cells |
sort |
(logical) Should the columns of the data.frame be sorted before? |
filter |
(logical) Filter the supplied data frame to remove very small sectors that may not be visible. The default is to not remove any sectors. |
cell_size |
(character) The name of the column used to control sector size.
Can be one of |
custom_color |
(character) An optional column that can be specified to
control cell color. Cell colors are determined when drawing the treemap
using |
diameter_inner |
(numeric) The minimum inner diameter of the drawn map. Defaults to 0.3, |
diameter_outer |
(numeric) The maximum outer diameter of the drawn map. Defaults to 0.8 |
verbose |
(logical) If verbose is TRUE (default is FALSE), basic information such as a success message is printed to the console. |
This function returns a treemap object instead of a plot. In order
to actually draw the treemap, use drawTreemap
.
'sunburstTreemap' returns an object of the formal class 'sunburstResult'. It is essentially a list of objects related to the graphical representation of the treemap (polygons, labels, cell data) as well as data from the call of the function. It contains the following slots:
cells |
'list' of polygons for drawing a treemap |
data |
'data.frame', the original data that was supplied to calling 'voronoiTreemap' |
call |
'list' of arguments used to call 'voronoiTreemap' |
drawTreemap
for drawing the treemap.
# load example data
data(mtcars)
mtcars$car_name = gsub(" ", "\n", row.names(mtcars))
# generate treemap;
# by default cell (sector) size is encoded by number of members per group
tm <- sunburstTreemap(
data = mtcars,
levels = c("gear", "cyl"),
cell_size = "hp"
)
# draw treemap with default options
drawTreemap(tm,
title = "A sunburst treemap",
legend = TRUE,
border_size = 2,
layout = c(1, 3),
position = c(1, 1)
)
# use custom color palette
drawTreemap(tm,
title = "Use custom palette",
legend = TRUE,
color_palette = rep(c("#81E06E", "#E68CFF", "#76BBF7"), c(3, 4, 5)),
border_size = 2,
label_level = 2,
label_size = 0.7,
label_color = grey(0.5),
layout = c(1, 3),
position = c(1, 2),
add = TRUE
)
# color cells (sectors) based on cell size
drawTreemap(tm,
title = "Coloring encoded by cell size",
color_type = "cell_size",
legend = TRUE,
color_palette = rev(heat.colors(10)),
border_size = 3,
border_color = grey(0.3),
label_level = 1,
label_size = 2,
label_color = grey(0.5),
layout = c(1, 3),
position = c(1, 3),
add = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.