简体   繁体   中英

How to get a good dendrogram using R

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")

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

在此处输入图片说明

ggplot

with ggplot and ggdendro

library(ggplot2)
library(ggdendro)

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM