I saw these codes from here: http://learnr.wordpress.com/2009/08/10/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-9/
hc1 <- hclust(dist(USArrests, method = "canberra"))
hc1 <- as.dendrogram(hc1)
ord.hc1 <- order.dendrogram(hc1)
hc2 <- reorder(hc1, state.region[ord.hc1])
ord.hc2 <- order.dendrogram(hc2)
region.colors <- trellis.par.get("superpose.polygon")$col
USArrests2 <- melt(t(scale(USArrests)))
USArrests2$X2 <- factor(USArrests2$X2, levels = state.name[ord.hc2])
But I’m very confused in the forth line about the state.region variable.
The variable about the order is ord.hc1 was generated from USArrests, which seems to have nothing to do with state.region. Then why it uses state.region for reordering instead of a column within USArrests data frame?
Look at the help file for
state.region–The first sentence under Details, is
This means that we can jump between the USA data sets, since they are all in the same order, i.e. the state of the first entry of the
USArrestsis the same as the state instate.region.