Skip to content
Back to formatted view

Raw Message

Message-ID: <CA+8X3fWdJPyiBtc83+gqWscOA-rXD-itsJGO=2eCecVmnKSu0g@mail.gmail.com>
Date: 2019-01-12T02:49:29Z
From: Jim Lemon
Subject: Overlapping legend in a circular dendrogram
In-Reply-To: <CAL1He1LVhXyxXEbX6OWrVz84FtjDFnCfr6ooXcRRZwfPkhrRbA@mail.gmail.com>

Hi Meriam,
I don't have the packages loaded that you use, but a first guess would
be to start a wider device. For example, the default x11 device is
7x7, so:

x11(width=10)

would give you a rectangular output device that might move the columns
of labels outward. The same applies for any other device, just
explicitly open the wider device before you run your code.

Jim

On Sat, Jan 12, 2019 at 3:29 AM N Meriam <meriam.nef at gmail.com> wrote:
>
> Dear all,
>
> I run the following code and I get this graphic (pdf attached). 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
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.