DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
|
> # 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) |