Description Usage Arguments Examples
Create interactive sunburst chart with the 'd2b' charting library.
1 2 |
data |
data in csv source,target form or in
nested d3 JSON hierarchy with 'name:..., children:[];'. |
colors |
|
valueField |
|
height, width |
height and width of sunburst htmlwidget containing div
specified in any valid |
elementId |
string id as a valid |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ## Not run:
# 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)
# change the colors
# using d3.js categorical color scheme
sund2b(
sequences,
colors = htmlwidgets::JS("d3.scaleOrdinal(d3.schemeCategory20b)")
)
# 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.