Skip to main content
Link
Menu
Expand
(external link)
Document
Search
Copy
Copied
Documentation
Document Digital Tools
R Language
Overview of R Material
R Syllabus
Background R Material
R Language Tips & Tricks
Douglas Bates Stat 692 Notes
R References
Curate R Data
Visualize Data with R
Network Observatins in Connected Graphs
Visualization & Graphics Links
Analyze Data
Systems Genetics
Profile & Simulate
Connect Data Tools Beyond `R`
Communication & Writing
Docker and Guix
Going Beyond R
LaTeX Writing Language
Linux Operating System & bash Shell
Non-Traditional Students: Professional MS and Certificates
Online & Blended Courses in Statistics
Professional Programs in Data Science or Data Analytics
Professional Skills for Data Science
R for teams in the data sciences
Reproducible Research Tools
Scaling up the split-apply-combine paradigm
Software Packages, Languages & Writing Tools
Stat 692 Fall 2014 Notes
Organize Data & Docs
R in VS Code with Radian
Python Language
Python Coding Strategy
Python Default Kernel for Quarto
Organize Projects with GitHub
Publish GitHub Pages
Embed Objects in GitHub Pages
Automate with GitHub Actions
Prepare Shinylive App Export
Publish Quarto Dashboard
Deploy Shinylive Apps
Version GitHub Docs
Environmental Systems
Geospatial Resources
Shiny Apps
AI (Artificial Intelligence)
AI Environments
Recovering Antigravity 1.x Conversations
Large Language Models (LLMs)
Team Science Platforms
Prompt Engineering
Prompt Examples
Version GitHub Docs
Assemble Powerpoint
Create Quarto Slides
Refactor Workflows
Configure Just-the-Docs
Check External Links
AGENTS.md — Documentation Repository
AGENTS_mini.md (Mini)
Migrate Documentation from DSHub
Context Engineering
Quarto Slides & References
Data Science
Big Data
Data Repositories
Documentation Source
Search Documentation
Examples pulled from **Network Visualization with R**, [Polnet 2016](http://www.kateto.net/polnet2016) by Katya Ognyanova. ```{r} suppressPackageStartupMessages({ library(RColorBrewer) library(readr) library(dplyr) library('visNetwork') }) ``` ```{r} data_dir <- "Data files" ``` Here use [visNetwork](http://datastorm-open.github.io/visNetwork/) package. visNetwork enables setting graphic properties as node or edge attributes by adding them as data columns before calling `visNetwork()`. See available options with: ```{r eval=FALSE} ?visNodes ?visEdges ``` For more information, see: ```{r eval=FALSE} ?visOptions # available options ?visLayout # available layouts ?visGroups # using node groups ?visLegend # adding a legend ``` ### Basic visNetwork with Dataset 1 ```{r} nodes <- read_csv(file.path(data_dir, "Dataset1-Media-Example-NODES.csv")) links <- read_csv(file.path(data_dir, "Dataset1-Media-Example-EDGES.csv")) %>% group_by(from,to,type) %>% summarize(weight = sum(weight)) %>% ungroup %>% arrange(from,to) ``` Open dataset 1 with visNetwork. ```{r} visNetwork(nodes, links, width="100%", height="400px", main="Network!") ``` Changing some node parameters: * shape (ellipse, circle, database, box, text, image, circularImage, diamond, dot, star, triangle, triangleDown, square, icon) * color.background (node color) * color.border (frame color) * color.highlight (color on mouse click) * color.hover (color on mouseover) ```{r} 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) ``` Set up hover option. ```{r} nodes$color.hover.background <- "green" visNetwork(nodes, links) %>% visInteraction(hover = TRUE) ``` Change visual properties of edges. ```{r} links$width <- 1 + links$weight/8 # line width links$color <- "gray" # line color links$arrows <- "middle" # arrows: 'from', 'to', or 'middle' links$smooth <- FALSE # should the edges be curved? links$shadow <- FALSE # edge shadow visNetwork(nodes, links) ``` `visNetwork` offers a number of other options in the `visOptions()` function. For instance, highlight all neighbors of a selected node (`highlightNearest`), or add a drop-down menu to select groups of nodes (`selectedBy`). The groups are based on data columns such as `type label`. ```{r} visNetwork(nodes, links) %>% visOptions(highlightNearest = TRUE, selectedBy = "type.label") ```