sund2b | R Documentation |
Create interactive sunburst chart with the 'd2b' charting library.
sund2b( data = NULL, colors = NULL, valueField = "size", tooltip = NULL, breadcrumbs = NULL, rootLabel = NULL, showLabels = FALSE, width = NULL, height = NULL, elementId = NULL )
data |
data in csv source,target form or in
nested d3 JSON hierarchy with 'name:..., children:[];'. |
colors |
|
valueField |
|
tooltip |
|
breadcrumbs |
|
rootLabel |
|
showLabels |
|
height, width |
height and width of sunburst htmlwidget containing div
specified in any valid |
elementId |
string id as a valid |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.