In this tweet announcing this blog post, @revoandrie visualized his UseR 2015 CRAN network talk with networkD3
.
I thought it would be a good opportunity to show a couple more htmlwidgets
.
library(igraph)
# devtools::install_github("chrisotphergandrud/networkD3")
library("networkD3")
# devtools::install_github("rich-iannone/DiagrammeR")
# //rich-iannone.github.io/DiagrammeR
library("DiagrammeR")
# devtools::install_github("dataknowledge/visNetwork")
# //dataknowledge.github.io/
library("visNetwork")
## Loading required package: magrittr
This is all code directly from @revoandrie’s gist.
url <- "//rawgit.com/andrie/cran-network-structure/master/pdb/depGraph-CRAN.rds"
datafile <- tempfile(fileext = ".rds")
download.file(url, destfile = datafile, mode = "wb")
gs <- readRDS(datafile)
# Remove all nodes with fewer than 50 edges
deg <- degree(gs, mode = "out")
idx <- names(which(deg > 50))
gn <- induced.subgraph(gs, idx)
# Extract into data frame and plot
gd <- get.data.frame(gn, what = "edges")
simpleNetwork(gd, fontSize = 12, height = 600, width = "100%")
I’ll keep the code and customization to hopefully provide a fair comparison.
DiagrammeR
gives us a couple different options, but the most interactive is vivagraph
.
library(htmltools)
# can handle igraph directly
vivagraph(gn,height = 600,width = "100%")
# can even use igraph layouts
vivagraph(gn, layout = layout.auto,height = 600,width = "100%")
visNetwork
in my opinion gives the most full-featured interactive network visualization currently.
# use visNetwork
# get a size for our nodes
V(gn)$size <- degree(gn) * 10
gn %>%
get.data.frame( what = "both" ) %>%
{
visNetwork(
nodes = data.frame(
id = .[["vertices"]][,"name"]
,size = .[["vertices"]][["size"]]
)
,edges = .[["edges"]]
,height = 600
,width = "100%"
)
} %>%
visOptions(highlightNearest = TRUE)