A sunburst plot represents hierarchial data as sectors laid out over several levels of concentric rings.
Usage
px_sunburst(
data_frame = NULL,
names = NULL,
values = NULL,
parents = NULL,
path = NULL,
ids = NULL,
color = NULL,
color_continuous_scale = NULL,
range_color = NULL,
color_continuous_midpoint = NULL,
color_discrete_sequence = NULL,
color_discrete_map = NULL,
hover_name = NULL,
hover_data = NULL,
custom_data = NULL,
labels = NULL,
title = NULL,
subtitle = NULL,
template = NULL,
width = NULL,
height = NULL,
branchvalues = NULL,
maxdepth = NULL
)Arguments
- data_frame
A data.frame, data.table, list or matrix. Needed for column names to be used in the other arguments; if
NULL, a data frame is built from the vectors given in the other arguments.- names
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used as labels for sectors.- values
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to set values associated to sectors.- parents
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used as parents in sunburst and treemap charts.- path
Column names in
data_frame(a character vector or a formula such as~c(a, b)), or a list of column names, formulas and vectors. The columns define the hierarchy of sectors, from root to leaves. Cannot be combined withidsorparents.- ids
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to set ids of sectors- color
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign color to marks.- color_continuous_scale
Character vector of colors, e.g.
px_colors$sequential$Viridis, or the name of a scale in px_colors. Used whencoloris numeric. Defaults to the template's sequential colorscale.- range_color
If provided, overrides auto-scaling on the continuous color scale.
- color_continuous_midpoint
If set, computes the bounds of the continuous color scale to have the desired midpoint. Setting this value is recommended when using
plotly.express.colors.divergingcolor scales as the inputs tocolor_continuous_scale.- color_discrete_sequence
Character vector of colors, e.g.
px_colors$qualitative$Set1. Values ofcolorare assigned colors in order (cycling), unless set incolor_discrete_map. Defaults to the template'scolorway.- color_discrete_map
Named character vector or list mapping values of
colorto colors, overridingcolor_discrete_sequence. If the values ofcolorare colors,px_identity()(or"identity") uses them directly.- hover_name
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector appear in bold in the hover tooltip.- hover_data
Extra data to show in the hover tooltip: column names (a character vector or a formula such as
~c(a, b)), or a named list with column names as names and valuesTRUE(default formatting),FALSE(hide the column, e.g. one shown by default), a d3-format string such as":.3f", a vector of data, or a list of a format string orTRUEand a vector of data.- custom_data
Column names (a character vector or a formula such as
~c(a, b)), or a list of column names, formulas and vectors. Values from these columns are added to the traces'customdata(e.g. for use in Shiny events) without appearing in the hover tooltip.- labels
Named character vector or list mapping column names to the labels to use for axis titles, legend entries and hover text, e.g.
c(gdpPercap = "GDP per capita").- title
The figure title.
- subtitle
The figure subtitle.
- template
A template name (see
template_names()) or a template list. Defaults todefault_template().- width
The figure width in pixels.
- height
The figure height in pixels.
- branchvalues
"total" or "remainder" Determines how the items in
valuesare summed. Whenset to "total", items invaluesare taken to be valueof all its descendants. When set to "remainder", itemsinvaluescorresponding to the root and the branches:sectors are taken to be the extra part not part of thesum of the values at their leaves.- maxdepth
Positive integer Sets the number of rendered sectors from any given
level. Setmaxdepthto -1 to render all thelevels in the hierarchy.
Value
A go_figure().
See also
Other plotly express:
px_area(),
px_bar(),
px_bar_polar(),
px_box(),
px_choropleth(),
px_choropleth_map(),
px_density_contour(),
px_density_heatmap(),
px_density_map(),
px_ecdf(),
px_funnel(),
px_funnel_area(),
px_histogram(),
px_icicle(),
px_imshow(),
px_line(),
px_line_3d(),
px_line_geo(),
px_line_map(),
px_line_polar(),
px_line_ternary(),
px_parallel_categories(),
px_parallel_coordinates(),
px_pie(),
px_scatter(),
px_scatter_3d(),
px_scatter_geo(),
px_scatter_map(),
px_scatter_matrix(),
px_scatter_polar(),
px_scatter_ternary(),
px_strip(),
px_timeline(),
px_treemap(),
px_violin()
Examples
px_data_tips() |> px_sunburst(path = ~c(day, time, sex), values = ~total_bill)