Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active December 9, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/a4dd5b56dd34537e3ed4ed3db39df35f to your computer and use it in GitHub Desktop.
Save knbknb/a4dd5b56dd34537e3ed4ed3db39df35f to your computer and use it in GitHub Desktop.
Creates a static HTML/JS page with pretty network-diagram of twitter data (captured by gephi)
# create pretty network-diagram of tweets,
# captured with Gephi's Twitter plugin,
# exported as JSON
# knbknb 20181218
#
library(visNetwork)
library(readr)
workdir <- "/home/knut/gephi/"
# infile created with "Export as ..." Feature of Gephi Desktop App
# in-memory representation is stringified JSON
infile <- "rstats.json"
outfile <- paste0(workdir, infile, ".html")
gephi_json_str <- readr::read_file(file.path(workdir, infile))
# enable_phys = FALSE:
# - much shorter rendering times even for larger graphs
# - layout is ugly
# enable_phys = TRUE:
# - startup + rendering time can be several minutes
# - layout is better (repulsion between nodes)
enable_phys <- FALSE
nw <- visNetwork::visNetwork(
gephi = gephi_json_str,
width = 2000, height = 2000
) %>%
visPhysics(enabled = enable_phys)
visSave(nw, outfile)
# open in a web browser on linux
browseURL(url = outfile, browser = "google-chrome")
@knbknb
Copy link
Author

knbknb commented Dec 9, 2018

Output will look like this

slow startup, long loading times (with enable_phys=TRUE)

rstats-graph-2

loads faster (with enable_phys=FALSE)

rstats-graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment