Customization of Sunburst diagram with sunburstR in R

Viewed 35

I am trying to customize the Sunburst diagram created using the sunburstR package. I want to change the font size of the categories in the Legend. And, I want to change the color scheme of the diagram too. Any help is appreciated. Below is my code:

sunburst(sequence, percent=TRUE,count=TRUE)
1 Answers

For the colors you can just use a colors argument like this:

library(sunburstR)
library(tidyverse)
sequences <- read.csv(system.file("examples/visit-sequences.csv",package="sunburstR"),header = FALSE,stringsAsFactors = FALSE)[1:100,]
sunburst(sequences, percent=TRUE, count=TRUE,
         colors = c("#111d4a","#ffcf99","#92140c","#1e1e24", "#fff8f0", "#0b7a750"))

Output:

enter image description here For the font-size, you can do this by using htmlwidgets to add JavaScript code like in this post:

library(htmlwidgets)
sun <- sunburst(sequences, percent=TRUE, count=TRUE,
                colors = c("#111d4a","#ffcf99","#92140c","#1e1e24", "#fff8f0", "#0b7a750"))
htmlwidgets::onRender(
  sun,
  "
    function(el, x) {
    d3.selectAll('.sunburst-legend text').attr('font-size', '30px');
    }
    "
)

Output:

enter image description here

Related