**Feb 9, 2013: I tried running these codes in igraph v0.6, R 2.15 and all seems to be working ok.
Now that I have described how to add node attributes to network figures, I will introduce how to add edge values or edge weights to your network. Simply put, we are now moving from a 0-1 adjacency matrix to a matrix that can have a continuous range of values. I illustrate the basic approach in igraph first, and then I show the equivalent codes for statnet below.
For example, consider our hypothetical network of birds--but now some birds are associated more strongly with each other than others. This could be that these individuals are associated in foraging groups more often, or that they interact more frequently with each other than with other individuals--whatever fits your study.
This matrix is available in .csv form at the bottom of the page as an attachment.
... and we'll also make use of the information on sex of individuals as shown before:
This is again available at the bottom of the page as a .csv file.
Now I'll break down the codes, which are nearly identical to what I have shown in previous pages, save for a few critical differences.
That is all that is needed to make a weighted network in igraph: set weighted=TRUE when importing the matrix. We can confirm that the network is weighted simply by calling graph object:
IGRAPH UNW- 7 10 --
attr: name (v/c), weight (e/n)
Note that we now have an "edge attribute" called weight. This means that edges have values, and this has been assigned an object name. To call up the edge values, we simply use:
Which will show this:
So, we simply use E(net)$weight as part of the options for the network plot:
This should produce a figure that looks something like this:
Here's the full set of codes to produce a figure of the weighted network, with nodes color coded by sex:
The color-coding of sexes is identical to what was presented in the previous "using node attributes" section.
... in this hypothetical example, I made the matrix such that edges between males and females are stronger than edges between individuals of the same sex.
***** Weighted edges in Statnet ******
Unfortunately, loading a weighted network in statnet is slightly more complicated.
The first step is to create a network object while specifying "ignore edge values = false" and also storing the edge values as an edge attribute:
Now you have a network object named "net" that is a weighted network. Here's what the summary(net) function will call:
What you see here is that the 'adjacency matrix' of this network will still show only the 0-1 values. However, an edge attribute 'value' has the edge weights stored. In order to show the sociomatrix with the actual edge weights, you need to use something like this:
which will show:
To plot the network with edge weights, use:
net%e%'value' in statnet calls the edge attribute named 'value'. (It is equivalent to the notation E(net)$value in igraph)
Here are the full codes that will replicate the color-coded and weighted network figure in statnet, using the same .csv files:
*note the few unfamiliar options in the gplot() function: vertex.cex is the expansion factor for vertex size. vertex.sides is the number of sides that the vertex has--the default is 8. With about 20, the vertex looks like a circle. Also note that the default plotting algorithm in statnet is the Fruchterman-Reingold method, so the mode="fruchtermanreingold" here is redundant but I include it here for illustration purposes.
Here is the result: