Get startedGet started for free

ggnetwork Basics

In the last lesson, you saw that the ggnet2 package produces ggplot2-like plots with a reasonably familiar syntax to igraph. However, the ggnetwork package works a bit differently. It converts igraph objects into data frames that are easily plotted by ggplot2. It also adds several new geoms that can be used to build plots. The ggnetwork() function converts the igraph object to a data frame, and some parameters are added into the data frame (in this case, the arrow gap parameter) and then can be plotted using ggplot. From there, you build your graph up with geom_edges() for edges and geom_nodes() for vertices. In this lesson we'll do two basic plots of the retweet graph, one with ggplot defaults, and one with some basic theming to look a bit nicer.

This exercise is part of the course

Case Studies: Network Analysis in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Call ggplot
___(
  # Convert retweet_samp to a ggnetwork
  ___(retweet_samp), 
  # Specify x, y, xend, yend
  aes(x = ___, y = ___, xend = ___, yend = ___)) +
  # Add a node layer
  ___ +
  # Add an edge layer
  geom_edges()
Edit and Run Code