Overlapping legend in a circular dendrogram

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Overlapping legend in a circular dendrogram

MeriamNF
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
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Fwd: Overlapping legend in a circular dendrogram

MeriamNF
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

______________________________________________
[hidden email] 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.

dendro.pdf (166K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Fwd: Overlapping legend in a circular dendrogram

MeriamNF
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Overlapping legend in a circular dendrogram

Bert Gunter-2
This is the 3rd time you've posted this. Please stop re-posting!

Your question is specialized and involved, and you have failed to provide a
reproducible example/data. We are not obliged to respond.

You may do better contacting the maintainer, found by ?maintainer, as
recommended by the posting guide for specialized queries such as this.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jan 11, 2019 at 12:47 PM N Meriam <[hidden email]> wrote:

> 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
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Overlapping legend in a circular dendrogram

MeriamNF
Yes I know. Sorry if I reposted this but it's simply because I've
received an email mentioning that the file was too big that's why I
modified my question and reposted it.
I don't want to oblige anyone to respond. I really thought the issue
was my file (too big so nobody received it).

Thanks for your understanding,
Best Myriam

On Fri, Jan 11, 2019 at 3:03 PM Bert Gunter <[hidden email]> wrote:

>
> This is the 3rd time you've posted this. Please stop re-posting!
>
> Your question is specialized and involved, and you have failed to provide a reproducible example/data. We are not obliged to respond.
>
> You may do better contacting the maintainer, found by ?maintainer, as recommended by the posting guide for specialized queries such as this.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Jan 11, 2019 at 12:47 PM N Meriam <[hidden email]> wrote:
>>
>> 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
>>
>> ______________________________________________
>> [hidden email] 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.



--
Meriam Nefzaoui
MSc. in Plant Breeding and Genetics
Universidade Federal Rural de Pernambuco (UFRPE) - Recife, Brazil

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Overlapping legend in a circular dendrogram

Jim Lemon-4
In reply to this post by MeriamNF
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 <[hidden email]> 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
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.