Skip to content

Instantly share code, notes, and snippets.

@andrie
Last active July 21, 2023 19:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andrie/2a0ee5ac50c4d23906d2 to your computer and use it in GitHub Desktop.
Save andrie/2a0ee5ac50c4d23906d2 to your computer and use it in GitHub Desktop.
Visualise graph using the networkD3 package
library("networkD3")
library("igraph")
# Download prepared igraph file from github
url <- "https://github.com/andrie/cran-network-structure/blob/master/pdb/depGraph-CRAN.rds?raw=true"
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment