library(networkdata)
library(igraph)
data("got")
<- got[[1]]
gotS1 plot(gotS1)
Network Visualization
Most network analytic tasks are fairly straightforward to do in R. But when it comes to visualizing networks, R may lack behind some standalone software tools. Not because it is not possible to produce nice figures, but rather because it requires some time to obtain pleasing results. Just take a look at the default output when plotting a network with the plot()
function.
It is definitely possible to produce nice figures with the igraph package (Check out this wonderful tutorial), yet it may take some time to familiarize yourself with the syntax. Additionally, most of the layout algorithms of igraph
are non-deterministic. This means that running the same plot call twice may produce different results.
In this part, you will learn the basics of ggraph
, the “ggplot2
of networks”, together with the graphlayouts
package, which introduces additional useful layout algorithms to R. Arguably, using ggraph
is not really easier than igraph
. But once the underlying principle of the grammar of graphics is understood, you’ll see that it is actually quite intuitive to work with.
Required libraries
To run all the code in this tutorial, you need to install and load several packages.
install.packages(c("igraph", "graphlayouts", "ggraph", "ggforce"))
::install_github("schochastics/networkdata") devtools
Make sure you have at least the version given below. Some of the examples may not be backward compatible.
packageVersion("igraph")
[1] '1.6.0'
packageVersion("graphlayouts")
[1] '1.1.1'
packageVersion("ggraph")
[1] '2.2.0'
packageVersion("networkdata")
[1] '0.2.1'
packageVersion("ggforce")
[1] '0.4.1'
igraph
is mostly used for its data structures and graphlayouts
and ggraph
for visualizations. The networkdata
package contains a huge amount of example network data that always comes in handy for learning new visualization techniques.
library(igraph)
library(ggraph)
Loading required package: ggplot2
library(graphlayouts)
library(ggforce)