When it comes to visualizing network graphs, the visNetwork package is powerful, customizable, and loads of fun. All you need is a data frame of nodes and a data frame of edges. The interactive plot lets you zoom, pan, and drag with the mouse. Try it!

library(visNetwork)
nodes <- data.frame(id = 1:3, label = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")

visNetwork is particularly handy when it comes to larger, more cumbersome graphs. As an example, let us plot the package dependency network of ggplot2. We get an igraph object from miniCRAN, and the default static plot is dense.

library(miniCRAN)
igraph <- makeDepGraph("ggplot2")
plot(igraph)
## Warning in layout_with_fr(graph, dim = dim, ...): '.Random.seed' is not an
## integer vector but of type 'NULL', so ignored

visNetwork has a slick igraph API.

library(visNetwork)
network_data <- toVisNetworkData(igraph)
nodes <- network_data$nodes
edges <- network_data$edges
edges$arrows <- "to"

The interactivity and ordered layout make all the difference.

library(magrittr)
visNetwork(nodes = nodes, edges = edges, width = "100%") %>%
  visHierarchicalLayout(direction = "LR") %>%
  visNodes(physics = FALSE) %>%
  visInteraction(navigationButtons = TRUE) %>%
  visEvents(type = "once", startStabilizing = "function(){this.fit()}") %>%
  visPhysics(stabilization = FALSE)