|
DATA MINING
Desktop Survival Guide by Graham Williams |
|
|||
pdf("graphics/rplot-network.pdf")
library(network)
cash <- matrix(c(0, 10000, 0, 0, 20000,
1000, 0, 10000, 0, 0,
5000, 0, 0, 0, 3000,
0, 1000000, 600000, 0, 0,
0, 50000, 0, 500000, 0),
nrow=5, byrow=TRUE)
## Label the entities
rownames(cash) <- colnames(cash) <- c("A", "B", "C", "D", "E")
## Create a network
cash.net <- network(cash)
## We can change the line widths to represent the magnitude of the
## cash flow. We uas a log transform to get integers for the line
## widths.
cash.log <- log10(cash) # Log 10 to get magnitude
cash.log[cash.log==-Inf] <- 0 # Set resulting -Infinty (log10(0)) values to 0
cash.mag <- round(cash.log) # Round them to
## We can also add color to indicate the magnitude. Use heat colours
## to indicate the magnitude of the cash flow, from yellow to red.
heat <- rev(heat.colors(max(cash.mag)))
cash.col <- cash.mag
for (i in 1:length(heat)) cash.col[cash.col==i] <- heat[i]
## Record the magnitude of cash coming into any label and use this to
## scale the entity labels.
entity.sizes <- round(log10(apply(cash, 2, sum)))
entity.sizes <- 1 + entity.sizes-min(entity.sizes)
entity.sizes <- 1 + entity.sizes/max(entity.sizes)
plot(cash.net, displaylabels=TRUE, usecurve=TRUE, mode="circle",
edge.lwd=cash.mag, edge.col=cash.col,
label.cex=entity.sizes, label.border=0)
dev.off()
|