Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google


Network Analysis



> # Load some data.
> 
> nodelist <-read.csv("data/nodes.csv")
> edgelist <- read.csv("data/edges.csv")
> nodes <- levels(as.factor(nodelist[[1]]))
> # Create a matrix to represent the network.
> 
> m <- matrix(data = 0, nrow=length(nodes), ncol=length(nodes))
> rownames(m) <- colnames(m) <- nodes
> apply(edgelist, 1, function(x) m[x[[1]], x[[2]]] <<- 1)



 [1] 1 1 1 1 1 1 1 1 1 1 1 1



> graph <- network(m, matrix.type="adjacency")
> # Now plot the network, without the nodes.
> 
> x11()
> par(xpd=TRUE)
> xy <- plot(graph, vertex.cex=5, vertex.col="white", vertex.border=0)
> # Get the some other data from the nodes and generate a plot for
> # each node and place them onto the network. Include a Key at some
> # empty space.
> 
> kl <- largest.empty(xy[,1], xy[,2], 2, 2)
> stars(nodelist[-1], labels=nodelist[[1]], locations=xy, draw.segments=TRUE,
        key.loc=c(kl$x, kl$y), add=TRUE)

Figure 10.1: A sample social network with visualisations of the entities.
Image sna:sample_network



Subsections

Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010