Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
R network visualizations
# 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
You can’t perform that action at this time.