본문 바로가기

R관련

circular dendrogram 그리기

728x90
반응형

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 cicular 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 enure that we don't overlap the label plot region (height specified by labelHeight), nor the central

# region of the plot (1-(dendHeight+labelHeight))

# to는 공식이 -labelHeight+0.95임

# from은 공식이 (1-(dendHeight+labelHeight))


ticks <- seq(from=(0.99-(dendHeight+labelHeight)), to=(-labelHeight+0.95), 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)-(((
0.99-labelHeight)-(0.99-(dendHeight+labelHeight)))/2), 0+0.14, "Height", cex=0.8)
draw.circle(x=0,y=0,radius = ticks[1:4],lty=2)

728x90
반응형

'R관련' 카테고리의 다른 글

liftover (genome location transformation)  (0) 2017.10.30
R 단축키들 (R shortcut key)  (0) 2017.10.24
gsub in r  (0) 2017.08.21
Complex heatmap  (0) 2017.08.18
plyr package  (0) 2017.08.01