**minimalR.com » r-bloggers**, and kindly contributed to R-bloggers)

In last week’s post I used R heatmaps to visualise the performance of NFL Quarterbacks in 2012. This was done in a 2 step process,

- Clustering QB performance based on the 12 performance metrics using hierarchical clustering
- Plotting the performance clusters using R’s pheatmap library

An output from the step 1 is the cluster dendrogram that represents the clusters and how far apart they are. Reading the dendogram from the top, it first splits the 33 QBs into 2 clusters. Moving down, it then splits into 4 clusters and so on. This is useful as you can move down the diagram and stop when you have the number of clusters you want to analyse or show and easily read off the members of each cluster.

An alternative way to visualise clusters is to use the distance matrix and transform it into a 2 dimensional representation using R’s multidimensional scaling function `cmdscale()`

.

QBdist <- as.matrix(dist(QBscaled))

QBdist.cmds <- cmdscale(QBdist,eig=TRUE, k=2) # k is the number of dimensions

x <- QBdist.cmds$points[,1]

y <- QBdist.cmds$points[,2]

plot(x, y, main="Metric MDS", type="n")

text(x, y, labels = row.names(QBscaled), cex=.7)

This works well when the clusters are well defined visually but when they’re not like in this case then it just raises questions why certain data points belong to one cluster versus another. For example, Ben Roethlisberger and Matt Ryan above. Unfortunately Mark Sanchez is still unambiguously in a special class with Brady Quinn and Matt Cassel.

**leave a comment**for the author, please follow the link and comment on his blog:

**minimalR.com » r-bloggers**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...