sunburstR

421 篇文章 14 订阅

I fell in love with this Sequences Sunburst by Kerry Rodden immediately when it wastweeted 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 SievertTraMineR 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.

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 sunburstRI 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

Thanks

Thanks so much

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值