Graphs in R

We will use the R package, igraph, for our graph analysis needs. We will leverage the arules package to manipulate our data. If you don't have them installed, proceed to install them as follows:

>  install.packages("arules")>  install.packages("igraph")

You can use the sessionInfo function from the utils package to look at the packages available for you in the current session.

Let's get started; create a simple graph, and plot it:

> library(igraph, quietly = TRUE)> simple.graph <- graph_from_literal(A-B, B-C, C-D, E-F, A-E, E-C)> plot.igraph(simple.graph)

This produces the following graph plot:

After including the igraph library, ...

Get R Data Analysis Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.