Creating dendrograms with colors and labels
The dendrogram plot in the previous example was all black and white. While making a good presentation, we would like this to be more informative. We would also like our audience to look at the dendrogram and immediately spot clusters and relationships among variables. We will now move a bit away from basic R plots and use a package called dendroextras
. A sample dendrogram is as follows:
Getting ready
For creating a plot that is easy to interpret and study, we would use the dendroextras
package.
For a better understanding on installing packages in R, please refer to the recipe Installing packages and getting help in R, in Chapter 1, A Simple Guide to R:
install.packages("dendroextras") library(dendroextras)
How to do it…
The dendrogram is constructed using the USArrests data available in R. The dataset consists of four variables (Assault, Murder, Rape, and Percent of Urban Population) in each of 50 states of the USA in 1973. We would load the USArrests...