R: Understanding the ggnetwork package and its usage with ggplot

351 views Asked by At

I am learning to plot network graph using ggplot2, igraph and ggnetwork. I am studying this webpage:

https://cran.r-project.org/web/packages/ggnetwork/vignettes/ggnetwork.html#geom_edges

However, I have some very basic questions in order to understand how the functions work. In the example under the heading 'geom_edges', the code is

ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) 
    + geom_edges(aes(linetype = type), color = "grey50") 
    + theme_blank()

I do not understand

  • how does it actually use the ggnetwork package in the statement. Is it implicitly? How?
  • what does x = x, y = y, xend = xend, yend = yend mean? What are x, y, xend and yend?
  • how do the parameters x, y, xend, yend relate to the data object n?

Many thanks!

1

There are 1 answers

0
Fr. On

As previous commenters have said, the x, xend, y and yend parameters in the example code, which are used to plot nodes and edges between them, work exactly like in geom_segment. The ggnetwork builds on ggplot2, so some knowledge of that package is required to work with it.

What the package brings on top of ggplot2 are functions like geom_edges: see its documentation for the full list of functions.