Week26 - sunburstR
July 02, 2015
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:
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.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
.
devtools::install_github("timelyportfolio/sunburstR")
Examples
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")
library(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(
paste0(
"https://gist.githubusercontent.com/kerryrodden/7090426/"
,"raw/ad00fcf422541f19b70af5a8a4c5e1460254e6be/visit-sequences.csv"
)
,header=F
,stringsAsFactors = FALSE
)
sunburst(sequence_data)
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.
library(TraMineR)
library(sunburstR)
library(pipeR)
# use example from TraMineR vignette
data("mvad")
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") %>>%
(
data.frame(
# appending "-end" is necessary for this to work
sequence = paste0(
gsub(
x = names(.$Freq)
, pattern = "(/[0-9]*)"
, replacement = ""
, perl = T
)
,"-end"
)
,freq = as.numeric(.$Freq)
,stringsAsFactors = FALSE
)
) %>>%
sunburst
Additional Reading
Fast Company’s To Take on HBO and Netflix, Youtube Had to Rewire Itself featuring Kerry Rodden and this sequences sunburst.
US Sirelines with a very nicely adapted
Sequences Sunburst
as a pedigree visualization for thoroughbred horsesUSERcycle blog post Behavior Flow
Sequences Sunburst
fork for Kaggle See Click Predict Fix
Thanks
Thanks so much
- Kerry Rodden for
Sequences Sunburst
- Ramnath Vaidyanathan and RStudio for
htmlwidgets
- all the contributors to
R
andJavaScript