v_sunburst: Create a Sunburst Chart

View source: R/layers.R

v_sunburstR Documentation

Create a Sunburst Chart

Description

Create a Sunburst Chart

Usage

v_sunburst(
  vc,
  mapping = NULL,
  data = NULL,
  name = NULL,
  drill = TRUE,
  gap = 5,
  ...,
  serie_id = NULL,
  data_id = NULL
)

Arguments

vc

A chart initialized with vchart().

mapping

Default list of aesthetic mappings to use for chart.

data

Default dataset to use for chart. If not already a data.frame, it will be coerced to with as.data.frame.

name

Name for the serie, only used for single serie (no color/fill aesthetic supplied).

drill

Drill-down function switch.

gap

Layer gap, supports passing an array to configure layer gaps layer by layer.

...

Additional parameters for the serie.

data_id, serie_id

ID for the data/serie, can be used to further customize the chart with v_specs().

Value

A vchart() htmlwidget object.

Examples


library(vchartr)

# Create a sunburst and auto hide labels
vchart(countries_gdp) %>%
  v_sunburst(
    aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD),
    gap = 10,
    labelAutoVisible = list(
      enable = TRUE
    ),
    labelLayout = list(
      align = "center",
      rotate = "radial"
    )
  )


# Custom tooltip
vchart(countries_gdp) %>%
  v_sunburst(
    aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD)
  ) %>% 
  v_specs_tooltip(
    mark = list(
      title = list(
        value = JS("val => val?.datum?.map(data => data.name).join(' / ')")
      )
    )
  )


# Custom layout options
vchart(countries_gdp) %>%
  v_sunburst(
    aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD),
    gap = 0,
    innerRadius = c(0, 0.4, 0.8),
    outerRadius = c(0.3, 0.7, 0.85),
    labelAutoVisible = list(
      enable = TRUE,
      circumference = 1
    ),
    labelLayout = list(
      list(
        align = "center",
        rotate = "tangential",
        offset = 0
      ),
      NULL,
      list(
        align = "start",
        rotate = "radial",
        offset = 15
      )
    )
  ) %>% 
  v_specs(padding = 70)

vchartr documentation built on April 12, 2025, 1:51 a.m.