All examples By author By category About

timelyportfolio

d3.js treemap of R htmlwidgets using d3treeR, treemap, dplyr

Ryan Hafen (@hafen) made us a really nice gallery of htmlwidgets which includes Github stars, forks, and watchers. Here is a quick treemap made from the experimental version of the htmlwidget d3treeR.

library(dplyr)
library(treemap)
# using experimental version of d3treeR
# devtools::install_github("timelyportfolio/d3treeR@experiment/bostock")
library(d3treeR)

# have a look at htmlwidgets gallery star count tree map
widget_gh = jsonlite::fromJSON("https://rawgit.com/hafen/htmlwidgetsgallery/gh-pages/github_meta.json")
widget_yaml = yaml::yaml.load_file("https://rawgit.com/hafen/htmlwidgetsgallery/gh-pages/_config.yml")

lapply(
  names(widget_gh)
  ,function(w){
    widget = NULL
    widget = Filter(function(x){x$"name" == strsplit(w,"_")[[1]][2]}, widget_yaml$widgets)
    if( !is.null(widget) && length(widget) >0 ){
      widget = widget[[1]]
      data.frame(
        author = widget$ghauthor
        ,widget = widget$name
        ,stars = widget_gh[[w]]$stargazers_count
        ,forks = widget_gh[[w]]$forks_count
        ,stringsAsFactors = FALSE
      )
    }
  }
) %>%
  bind_rows %>%
  treemap(
    index = c("author","widget")
    ,vSize = "stars"
    ,vColor = "stars"
    ,type = "value"
  ) %>%
  d3tree( rootname = "htmlwidgets" )