1

I am creating a dendrogram in R from the hclust function, I then used ape package to create and unrooted phylogeny (purely for visualisation) and plot it using basic R plot. This looks exactly how I want except I have 166 observations in 4 classes. This means the labels overlay and it looks like a jumbled mess. unrooted phlogeny

My question is how can I (if at all) jitter the labels so that they overlay as little as possible? I have messed around with different cex settings however they grouping stays tight no matter what value I pick.

library(RColorBrewer)
library("dendextend")
library("dendextendRcpp")
library(cluster)
library(ape)

# Try ward distance clustering
clust.compl = hclust(dist,method = 'ward.D2')
dend = as.dendrogram(clust.compl) 

# Color branches - using dendoextend and dendoextendRcpp
colors <- brewer.pal(4, "Dark2")

# Cut tree so as to color based on cluster
clus4 = cutree(clust.compl, h=heights_per_k.dendrogram(dend)["4"])

# Plot unrooted
plot(as.phylo(clust.compl), 
     type = "unrooted",
     edge.width = 2, edge.lty = 2,
     tip.color = colors[clus4],
     no.margin = TRUE,
     label.offset = 0.5
     )

Any help appreciated

Martin O Leary
  • 633
  • 2
  • 10
  • 29

1 Answers1

2

In my opinion, the use of a circular dendrogram is a valuable solution for your problem:

library(RColorBrewer)
library("dendextend")
library(cluster)
library(ape)

dst <- dist(mtcars)
clust.compl = hclust(dst,method = 'ward.D2')
dend = as.dendrogram(clust.compl) 
cols <- brewer.pal(4, "Dark2")
clus4 = cutree(clust.compl, h=heights_per_k.dendrogram(dend)["4"])

plot(as.phylo(clust.compl), type = "fan", tip.color=cols[clus4])

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • Thanks for the reply, however I do have a plot like this already (should have mentioned). I am specifically looking for the type of plot above with the hope of making the labels more legible - that I think would make for a better visualisation. – Martin O Leary Apr 28 '17 at 12:25
  • 1
    p.s.: note that dendextendRcpp is not required (not is it on CRAN any more) – Tal Galili May 03 '17 at 21:27