Created
May 7, 2017 20:08
-
-
Save djq/44fbc1646c197d05b14643a32453a68b to your computer and use it in GitHub Desktop.
R network visualizations
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
# examples from: http://kateto.net/network-visualization | |
library('igraph') | |
library('network') | |
library('sna') | |
library('ndtv') | |
library('visNetwork') | |
# load data | |
setwd('/Users/djq/Desktop/net-viz/data') | |
nodes <- read.csv("Dataset1-Media-Example-NODES.csv", header=T, as.is=T) | |
links <- read.csv("Dataset1-Media-Example-EDGES.csv", header=T, as.is=T) | |
# visualization - using | |
# library('visNetwork') | |
visNetwork(nodes, links, width="100%", height="400px", main="Network!") | |
# make graph | |
nodes$shape <- "dot" | |
nodes$shadow <- TRUE # Nodes will drop shadow | |
nodes$title <- nodes$media # Text on click | |
nodes$label <- nodes$type.label # Node label | |
nodes$size <- nodes$audience.size # Node size | |
nodes$borderWidth <- 2 # Node border width | |
nodes$color.background <- c("slategrey", "tomato", "gold")[nodes$media.type] | |
nodes$color.border <- "black" | |
nodes$color.highlight.background <- "orange" | |
nodes$color.highlight.border <- "darkred" | |
visNetwork(nodes, links) | |
# filtering | |
visNetwork(nodes, links) %>% | |
visOptions(highlightNearest = TRUE, | |
selectedBy = "type.label") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment