Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty dendrograms in R?

My dendrograms are horribly ugly, on the verge of unreadable, and usually look like this:

enter image description here

library(TraMineR)
library(cluster)
data(biofam)
lab <- c("P","L","M","LM","C","LC","LMC","D")
biofam.seq <- seqdef(biofam[1:500,10:25], states=lab)

ccost <- seqsubm(biofam.seq, method = "CONSTANT", cval = 2, with.missing=TRUE)
sequences.OM <- seqdist(biofam.seq, method = "OM", norm= TRUE, sm = ccost,     
with.missing=TRUE)

clusterward <- agnes(sequences.OM, diss = TRUE, method = "ward")
plot(clusterward, which.plots = 2)

What I would like to create is something like the following, meaning a round dendrogram, where the size of the labels can be carefully controlled so that they are actually visible:

enter image description here

How can I accomplish this in R?

like image 241
histelheim Avatar asked Jan 28 '14 15:01

histelheim


1 Answers

The following solution may not be optimal but worth a try:

library(ape)
CL1 <- as.hclust(clusterward)
CL2 <- as.phylo(CL1)
plot(CL2, type="fan", cex=0.5)

enter image description here

The main issue obviously being the fact that there is still too many objects, hence too many labels. To turn the labels off, use argument show.tip.label=FALSE. You can also get rid of the margins to occupy the complete device with no.margin=TRUE:

plot(CL2, type="fan", show.tip.label=FALSE, no.margin=TRUE)

enter image description here

like image 75
plannapus Avatar answered Oct 03 '22 01:10

plannapus