**This page was updated on Feb 3, 2013, using igraph 0.6 on R 2.15One of the greatest benefits of organizing your data as a
network is the ability to visualize the connections between the individuals (or
whatever your nodes may be). In some cases, the power of pattern detection by
the human eye may be extremely helpful in motivating further questions.
However, a great caution is needed— With that said, given a clear hypothesis for what you are looking for, you will likely be able to produce a beautiful figure that illustrates those patterns by using the appropriate algorithms. Both statnet and igraph give you this flexibility. Let’s start with the simple default figure, using a sample adjacency matrix ( ------- In igraph ------- `dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=FALSE) ` `m=as.matrix(dat) ` `g=graph.adjacency(m,mode="undirected",weighted=NULL,diag=FALSE) ` `plot.igraph(g)` `plot.igraph(g,layout=layout.circle)` You can also use custom layouts. Here, I'll set up the vertices on a line and then used curved edges. `l=matrix(c(1,2,3,4,5,6,7, 1,2,3,4,5,6,7),ncol=2) ` `plot.igraph(g,layout=l,edge.curved=TRUE)` By default, vertices are labeled by their node indexing number (which used to start with 0 in igraph 0.5 but now starts with 1 in igraph 0.6). You can alter the vertex label, vertex color and edge color, etc.: `plot.igraph(g,vertex.label=V(g)$name,vertex.size=30,,vertex.label.color="yellow", vertex.label.font=2,vertex.color="darkblue",edge.color="black")` For a ton more arguments you can use to make your network look pretty, see ?igraph.plotting
`library(statnet)` `# import matrix data and convert to a network object. You can find the data I use here in the "importing data" section - download the sample_adjmatrix.csv file:` `dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=FALSE)` `m=as.matrix(dat)` `net=network(m,matrix.type="adjacency",directed=FALSE)` `#open a graphic window and plot the network as an 'undirected' graph` `quartz()` `gplot(net)` ---------------------------------... you can see that the default of the gplot() command in statnet is to produce a “digraph”—that is, a graph with directionality. If you want simple lines rather than arrows, use: `quartz()` `gplot(net,gmode="graph")` -------------------------------------------------... Notice also that these two plots looks a bit different. However, they are identical as far as their network structure goes. The default algorithm for producing plots in
statnet is the Just as an example, here are two other plots of the exact same network, arranged in a circle and via multidimensional scaling: ------------------------------------------------- |

R Resources > Social Networks in R >