sund2b {sunburstR}R Documentation

Sunburst Using 'd2b'

Description

Create interactive sunburst chart with the 'd2b' charting library.

Usage

sund2b(
  data = NULL,
  colors = NULL,
  valueField = "size",
  tooltip = NULL,
  breadcrumbs = NULL,
  rootLabel = NULL,
  showLabels = FALSE,
  width = NULL,
  height = NULL,
  elementId = NULL
)

Arguments

data

data in csv source,target form or in nested d3 JSON hierarchy with 'name:..., children:[];'. list, character, or connection data will be assumed to be JSON. data.frame data will be assumed to be csvdata and converted to JSON by sunburstR:::csv_to_hier().

colors

vector of strings representing colors as hexadecimal for manual colors. If you want precise control of colors, supply a list with range and/or domain. For advanced customization, supply a JavaScript function.

valueField

character for the field to use to calculate size. The default value is "size".

tooltip

list of options for customizing the tooltip. See the helper function sund2bTooltip for more information.

breadcrumbs

list of options for customizing the breadcrumb. See the helper function sund2bBreadcrumb for more information.

rootLabel

character to label root node something other than 'root'.

showLabels

logical to show labels on the slices. The default is FALSE.

height, width

height and width of sunburst htmlwidget containing div specified in any valid CSS size unit.

elementId

string id as a valid CSS element id.

Examples

if(interactive()){

  # The sund2b() API mirrors sunburst() with fewer arguments.

  library(sunburstR)

  # use a sample of the sequences csv data
  sequences <- read.csv(
    system.file("examples/visit-sequences.csv",package="sunburstR")
    ,header = FALSE
    ,stringsAsFactors = FALSE
  )[1:200,]

  # create a d2b sunburst
  sund2b(sequences)

  # show labels
  sund2b(sequences, showLabels = TRUE)

  # change the colors
  #   using d3.js categorical color scheme
  sund2b(
    sequences,
    colors = htmlwidgets::JS("d3.scaleOrdinal(d3.schemeCategory20b)")
  )
}

## Not run: 
#  using RColorBrewer palette
sund2b(
  sequences,
  colors = list(range = RColorBrewer::brewer.pal(9, "Set3"))
)
#  using a color column from the R dataset
#  treemap has an amazing treecolors ability
library(treemap)
library(d3r)
rhd <- random.hierarchical.data()
tm <- treemap(
  rhd,
  index = paste0("index", 1:3),
  vSize = "x",
  draw = FALSE
)$tm
sund2b(
  d3_nest(tm, value_cols = colnames(tm)[-(1:3)]),
  colors = htmlwidgets::JS(
    # yes this is a little different, so please pay attention
    #  "function(d) {return d.color}" will not work
    "function(name, d){return d.color || '#ccc';}"
  ),
  valueField = "vSize"
)


# use sund2b in Shiny
library(shiny)
ui <- sund2bOutput("sun")
server <- function(input, output, session) {
  output$sun <- renderSund2b({
    sund2b(sequences)
  })
}
shinyApp(ui, server)


## End(Not run)

[Package sunburstR version 2.1.8 Index]