Last active
December 9, 2018 16:42
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output will look like this
slow startup, long loading times (with
enable_phys=TRUE
)loads faster (with
enable_phys=FALSE
)