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, we used the graph_from_literal
function to create a simple undirected graph with six nodes. The igraph
package provides the plot.igraph
function to visualize the graphs. There are several ways in which we can create a graph. For a complete list of the different methods available to create graphs, refer to http://igraph.org/r/#docs.
Alternatively...