4 min read

Week26 - sunburstR

Week26 - sunburstR

htmlwidgets News This Week

I can’t keep up with all that is happening in widget-world, so for all the newest and updated htmlwidgets, just do this Github search, and you’ll quickly get up to date.

Why My Naming Scheme?

For those who wonder if there is any reason why I name my htmlwidgets the way I do, the answer is yes. I append “R” to a short name for the widget. The appended “R” makes it much easier to track on Github. Without the appended “R”, it would quickly get confusing especially considering the number of htmlwidgets I have produced and the number of Github projects that I star/watch. I learned this lesson with svgPanZoom and parcoords. At one point I considered appending “-htmlwidget” to my widgets, but that seems much too long.

This Week’s Widget - sunburstR

I fell in love with this Sequences Sunburst by Kerry Rodden immediately when it was tweeted to the world in October 2013. I’ll put it in an iframe below to insure that you don’t miss it. It was also mentioned it back in the post Week 3 | More Network Layouts.

The additional request by Mark Riseley in this Github issue motivated me to attempt to squeeze this beauty into an htmlwidget

Breaking My Rules

This week I broke a number of my rules or best practices for htmlwidgets. My excuses follow:

  1. I really need help, input, feedback on this to determine direction and functionality. My twitter poll provided four potential use cases: hierarchical topic models from Carson Sievert, TraMineR state sequences from James Curley, thoroughbred sire pedigree family trees by Tom H, and VERIS security data by Bob Rudis.

  2. I did two widgets this week, since I missed last week due to vacation, and I just ran out of time.

Quick Installation

sunburstR is not yet on CRAN and won’t be unless someone asks, so for now please install with devtools::install_github.



Original Example but in R

The most obvious example is to recreate the original example but in R. Since I embedded the original in an iframe above, I’ll just post the code to demonstrate.

# devtools::install_github("timelyportfolio/sunburstR")


# read in sample visit-sequences.csv data provided in source
#   https://gist.github.com/kerryrodden/7090426#file-visit-sequences-csv
sequence_data <- read.csv(
  ,stringsAsFactors = FALSE


Example with TraMineR

TraMineR is a really, really nice R package for working with sequences.

Gabadinho, A., Ritschard, G., Müller, N.S. & Studer, M. (2011), Analyzing and visualizing state sequences in R with TraMineR, Journal of Statistical Software. Vol. 40(4), pp. 1-37.

Let’s adapt the first example from the TraMineR vignette so that we can visualize it with our new sunburstR. I apologize to the non-piping R world, but pipes make this so much easier.


# use example from TraMineR vignette
mvad.alphab <- c(
  "employment", "FE", "HE", "joblessness",
  "school", "training"
mvad.seq <- seqdef(mvad, 17:86, xtstep = 6, alphabet = mvad.alphab)

# to make this work, we'll compress the sequences with seqdss
#   could also aggregate with dply later
seqtab( seqdss(mvad.seq), tlim = 0, format = "SPS" ) %>>%
  attr("freq") %>>%
      # appending "-end" is necessary for this to work
      sequence = paste0(
          x = names(.$Freq)
          , pattern = "(/[0-9]*)"
          , replacement = ""
          , perl = T
      ,freq = as.numeric(.$Freq)
      ,stringsAsFactors = FALSE
  ) %>>%

Additional Reading


Thanks so much