[R] Fwd: Overlapping legend in a circular dendrogram
N Meriam
meri@m@nef @ending from gm@il@com
Fri Jan 11 21:38:37 CET 2019
Hi, I'm facing some issues when generationg a circular dendrogram.
The labels on the left which are my countries are overlapping with the
circular dendrogram (middle). Same happens with the labels (regions)
located on the right.
I run the following code and I'd like to know what should be changed
in my code in order to avoid that.
load("hc1.rda")
library(cluster)
library(ape)
library(dendextend)
library(circlize)
library(RColorBrewer)
labels = hc1$labels
n = length(labels)
dend = as.dendrogram(hc1)
markcountry=as.data.frame(markcountry1)
#Country colors
groupCodes=as.character(as.factor(markcountry[,2]))
colorCodes=rainbow(length(unique(groupCodes))) #c("blue","red")
names(colorCodes)=unique(groupCodes)
labels_colors(dend) <- colorCodes[groupCodes][order.dendrogram(dend)]
#Region colors
groupCodesR=as.character(as.factor(markcountry[,3]))
colorCodesR=rainbow(length(unique(groupCodesR))) #c("blue","red")
names(colorCodesR)=unique(groupCodesR)
circos.par(cell.padding = c(0, 0, 0, 0))
circos.initialize(factors = "foo", xlim = c(1, n)) # only one sector
max_height = attr(dend, "height") # maximum height of the trees
#Region graphics
circos.trackPlotRegion(ylim = c(0, 1.5), panel.fun = function(x, y) {
circos.rect(1:361-0.5, rep(0.5, 361), 1:361-0.1, rep(0.8,361), col =
colorCodesR[groupCodesR][order.dendrogram(dend)], border = NA)
}, bg.border = NA)
#labels graphics
circos.trackPlotRegion(ylim = c(0, 0.5), bg.border = NA,
panel.fun = function(x, y) {
circos.text(1:361-0.5,
rep(0.5,361),labels(dend), adj = c(0, 0.5),
facing = "clockwise", niceFacing = TRUE,
col = labels_colors(dend), cex = 0.45)
})
dend = color_branches(dend, k = 6, col = 1:6)
#Dendrogram graphics
circos.trackPlotRegion(ylim = c(0, max_height), bg.border = NA,
track.height = 0.4, panel.fun = function(x, y) {
circos.dendrogram(dend, max_height = 0.55)
})
legend("left",names(colorCodes),col=colorCodes,text.col=colorCodes,bty="n",pch=15,cex=0.8)
legend("right",names(colorCodesR),col=colorCodesR,text.col=colorCodesR,bty="n",pch=15,cex=0.35)
Cheers,
Myriam
More information about the R-help
mailing list