knitr::opts_chunk$set(echo = TRUE)

Case Studies

USA Arrests

This is a simple example to show the versatility of the package.

1 - Clusterize the data from the USA Arrests dataset.

hc <- hclust(dist(USArrests), "ave")

2 - Convert the hclust to an igraph object.

gg <- hclust2igraph(hc)

3 - Set the nodes names.

idx <- which(V(gg$g)$name %in% hc$labels)
V(gg$g)$nodeAlias <- V(gg$g)$name

4 - Create the color pallete based on the murder rate for each state.

murder <- USArrests$Murder
qnts <- quantile(murder, seq(0, 1, 0.2))
pal <- brewer.pal(5, "Reds")
col <- rep(NA, length(murder))
col[murder < qnts[2]] <- pal[1]
col[murder >= qnts[2] & murder < qnts[3]] <- pal[2]
col[murder >= qnts[3] & murder < qnts[4]] <- pal[3]
col[murder >= qnts[4] & murder < qnts[5]] <- pal[4]
col[murder >= qnts[5] & murder <= qnts[6]] <- pal[5]
names(col) <- rownames(USArrests)


leonardokume/TreeAnfLeaf documentation built on May 6, 2019, 9:09 a.m.