Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Networks

Network graphs, as might be used in social network analysis, link analysis, or network analysis, are useful in presenting visualisations that we can explore for patterns.

A simple graph.



> library(igraph)
> my.df <- data.frame(e1=c(0.0, 0.5, 0.3), e2=c(0.2, 0.0, 0.6), e3=c(0.6, 0.4, 0.0))
> rownames(my.df) <- c("e1", "e2", "e3")
> my.df



    e1  e2  e3
e1 0.0 0.2 0.6
e2 0.5 0.0 0.4
e3 0.3 0.6 0.0



> my.graph <- graph.adjacency(as.matrix(my.df), weighted=TRUE)
> V(my.graph)$label <- V(my.graph)$name
> V(my.graph)$shape <- "rectangle"
> V(my.graph)$color <- "white"
> V(my.graph)$size <- 40
> my.mst <- minimum.spanning.tree(my.graph)
> my.layout <- layout.reingold.tilford(my.graph, mode="all")
> plot(my.mst, layout=my.layout)

Image dmsurvivor-rgraphics:plot_mst

Another example, showing a "tree" network with each node replaced by a plot. This should move into the "understanding" chapter as it is useulf if the bars were a profile of the means of a cluster and we put this into a dendrogram and so we can visualise the hierarchical clsuter?



> library(diagram)
> library(Hmisc)
> nnodes <- 7
> labs <- letters[1:nnodes]
> M <- matrix(nrow=nnodes, ncol=nnodes, byrow=TRUE, data=0)
> colnames(M) <- rownames(M) <- labs
> M["a", "b"] <- "Sunshine"
> M["a", "c"] <- "Humidity"
> M["b", "d"] <- "Rain"
> M["b", "e"] <- "Temp"
> M["c", "f"] <- "Cloud9"
> M["c", "g"] <- "Cloud3"
> pp <- plotmat(M, pos=c(1,2,4), curve=0, name="", shadow.size=0, lwd=1, box.lwd=0,
                cex.txt=0.8, box.size=0.05, box.prop=0.5, main="Sample Tree")
> ds <- rnorm(5000)
> for(i in 1:nnodes)
    subplot(hist(ds[runif(100, 1, length(ds))],
                 main="", xlab="", ylab="", axes=FALSE, col="grey90",
                 breaks="fd", border=TRUE),
            pp$comp[i,1], pp$comp[i,2])

Image dmsurvivor-r:graphics:tree_with_plots_at_nodes



Copyright © 2004-2010 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