[R] Overlapping legend in a circular dendrogram

N Meriam meri@m@nef @ending from gm@il@com
Thu Jan 10 21:34:22 CET 2019


Dear all,

I run the following code and I get this graphic (Imageattached). What
should I change in my code in order to adjust the overlapping objects?

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)

Thanks,
Meriam


More information about the R-help mailing list