1

I am using R to do a hierarchical cluster analysis using the Ward's squared euclidean distance. I have a matrix of x columns(stations) and y rows(numbers in float), the first row contain the header(stations' names). I want to have a good dendrogram where the name of the station appear at the bottom of the tree as i am not able to interprete my result. My aim is to find those stations which are similar. However using the following codes i am having numbers (100,101,102,...) for the lower branches.

Yu<-read.table("yu_s.txt",header = T, dec=",")
library(cluster)
agn1 <- agnes(Yu, metric = "euclidean", method="ward", stand = TRUE)
hcd<-as.dendrogram(agn1)

par(mfrow=c(3,1))

plot(hcd, main="Main")
plot(cut(hcd, h=25)$upper, 
     main="Upper tree of cut at h=25")
plot(cut(hcd, h=25)$lower[[2]], 
     main="Second branch of lower tree with cut at h=25")
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
Sevian
  • 57
  • 7

1 Answers1

2

A nice collection of examples are present here (http://gastonsanchez.com/blog/how-to/2012/10/03/Dendrograms.html)

Two methods:

with hclust from base R

hc<-hclust(dist(mtcars),method="ward")
plot(hc)

Default plot

enter image description here

ggplot

with ggplot and ggdendro

library(ggplot2)
library(ggdendro)

# basic option
ggdendrogram(hc, rotate = TRUE, size = 4, theme_dendro = FALSE)

enter image description here

Silence Dogood
  • 3,587
  • 1
  • 13
  • 17
  • +1 For nice examples as well as for an easy to interpret, useful example of how to rotate a dendrogram (flip dendrogram 90 degrees). Adding this comment so that it is easier to find with Google. – Timur Shtatland Nov 13 '19 at 16:19