Social networks analysis has received special attention over the past decade, and a lot of tools for manipulating and rendering social networks have emerged. In several situations a social network is associated with a spatial dimension, and behaviors observed within the network cannot be interpreted without taking into account the location of each of its nodes regarding to the other nodes. This is the case, for example, when studying inflows/outflows between cities or companies, or when studying people debating in a room. Based on the sp package, which provides efficient classes for storing spatial data and methods for handling and rendering them, the spnet package aims at facilitating the rendering of (social) networks on maps. Furthermore, fixing network node positions allows to more easily monitor time-varying networks and observe how connections and flows evolve over time.

The spnet package offers methods for dealing with spacial social networks. It allows to plot networks for which actors have a specific location on a map (participants in a political debate, cities, etc.). SpatialPolygons objects from the sp package are supported.

global.par.mar <- c(0,0,0,0)



Creating a spnet object

Creating a new spnet object (formal class SpatialNetwork) is done by the spnet.create function. You will have to supply two required parameters: the node IDs, and the corresponding position IDs on the map (which will be set in a second step). Note that in a spnet object data are stored in a data.frame. In this data.frame the two required parameters will be supplied as variables 'NODE' and 'POSITION'. Here is an example:

node <- c("France", "United States", "Brazil", "Australia")

# We load the world map

# We retrieve position IDs for our nodes
# As countries are numbered from 0 to 245 on the map, we subtract 1
position <- match(node,[,'NAME']) - 1

net1 <- spnet.create(
    'NODE' =  node,
    'POSITION' = position

## [1] "SpatialNetwork"
## attr(,"package")
## [1] "spnet"

Setting a map

The next step is to define the map to use for plotting. This is done with the function. Currently only SpatialPolygons objects are supported. If your map comes on another format (e. g. a shape file .shp) you can use instead the facilities of the maptools package to convert your map data into a SpatialPolygons object.

Setting labels

The IDs for nodes have to be valid variable names. You should avoid special character or spaces. Currently network data have to be provide as a matrix, with node IDs in row names an column names. Thus, the spnet object will automatically match your network data with the node positions on the map. To be valid row and column names, node IDs must not contain special characters or spaces.

In case you need to have more suitable label for your nodes when plotting the spnet object (e.g. containing spaces or accented characters), here is the protocol to follow:

First, we start with our basic spnet object containing a simple room map:

net1 <-

Then we introduce the data. In this case we use the following frame/matrix as an example:

##            NODE POSITION
## 1        France       64
## 2 United States      208
## 3        Brazil       20
## 4     Australia        8
## 5    Antarctica      144
net1$label <- c("France", "United States", "Brazil", "Australia", "Antartica")
graph.label.variable(net1) <- 'label'

Now you can change the size and the color of labels:

graph.label.cex(net1) <- 0.7
graph.label.color(net1) <- '#FF0000'