What a wonderful solution! Thank you very much!
how to draw circular dendrogram with distance information
I want draw circular dendrogram with R. I used dendextend package and followed example instructions.
However there is no description for annotatining height(distance) information. How to visualize height information?
Distance matrix
mat=matrix(abs(rnorm(100)),10,10);dimnames(mat)=list(letters[1:10],letters[1:10]) ma2=as.dist(mat)
dendrogram with distance info
hc=hclust(ma2)
dend=as.dendrogram(hc)
plot(dend)
Circular dendrogram without distance info (How to add height info for circular dendrogram?
library(dendextend)
circlize_dendrogram(dend = dend)
• 5,319 views
•
link
1 answer
The function does not appear to draw the height axis for some reason. I have neither seen much examples of it online - all circular dendrograms appear to omit it. So, I embarked on a task to add it myself.
The following code appears to do it:
mat <- matrix(abs(rnorm(100)),10,10)
dimnames(mat) <- list(letters[1:10],letters[1:10])
ma2 <- as.dist(mat)
hc <- hclust(ma2)
dend <- as.dendrogram(hc)
par(mfrow=c(1,2))
plot(dend)
require(circlize)
require(dendextend)
#Get the heights for each branch
heights <- round(get_branches_heights(dend, sort=FALSE), 1)
#Get max height
maxHeight= max(heights)
#Set label and dendrogram height for circular dendrogram
labelHeight=0.1
dendHeight=0.8
#Draw the circular dendrogram
circlize_dendrogram(dend,
facing = "outside",
labels = TRUE,
labels_track_height = labelHeight,
dend_track_height = dendHeight)
# Create tick co-ordinates and values for the new axis
# We have to ensure that we don't overlap the label plot region
# (height specified by labelHeight), nor the central region of the
# plot (1-(dendHeight+labelHeight))
ticks <- seq(from = (1-(dendHeight+labelHeight)),
to = (1-labelHeight), length.out=5)
values <- round(rev(seq(from=0, to=maxHeight, length.out=5)), 1)
#Add the new axis
require(plotrix)
ablineclip(h=0, v=ticks, col="black",
x1=1-(dendHeight+labelHeight),
x2=1-labelHeight,
y1=0,
y2=0.04,
lwd=1.5)
text(ticks, 0+0.08, values, cex=0.8)
text(
(1-labelHeight)-(((1-labelHeight)-(1-(dendHeight+labelHeight)))/2),
0+0.14,
"Height", cex=0.8)
• 0 views
•
link
• 0 views
•
link
You're welcome! - thanks.
• 0 views
•
link
Log in to answer this question.
