bernatgel / karyoploteR

karyoploteR - An R/Bioconductor package to plot arbitrary data along the genome
https://bernatgel.github.io/karyoploter_tutorial/
297 stars 42 forks source link

Rotated or staggered chromosome label, las argument? #110

Closed zx8754 closed 2 years ago

zx8754 commented 2 years ago

I looked through the karyoploteR tutorials couldn't find solution, apologies if this was already implemented.

When we plot as below, the chromosome labels overlap for chr17 to chr22

kp <- plotKaryotype(genome = "hg19", plot.type = 4,)
kpDataBackground(kp)

image

Any chance we could have labels vertical, as in las = 3 in base R:

las numeric in {0,1,2,3}; the style of axis labels. 0: always parallel to the axis [default], 1: always horizontal, 2: always perpendicular to the axis, 3: always vertical.

Alternatively, have it staggered?

image

zx8754 commented 2 years ago

OK, found it, of course it is implemented, srt = 90 would rotate it:

kp <- plotKaryotype(genome = "hg19", plot.type = 4, srt = 90)
kpDataBackground(kp)

image

Any chance we can have staggered option?

bernatgel commented 2 years ago

Hi @zx8754

Glad you found a solution. I usually use 45 degrees instead of 90, but it's a question of preferences. Also, take into account that that srt will also rotate the main title if there is one!

I had not thought about the staggered option, which makes a lot of sense. I'm pretty sure you can achieve this with a bit of hacking right now:

You should:

Something along the lines of

library(karyoploteR)

kp <- plotKaryotype(genome = "hg19", plot.type=4, labels.plotter=NULL)

evens <- ((1:length(chr.names))%%2)==0

chr.names <- kp$chromosomes
even.names <- chr.names
even.names[!evens] <- ""

odd.names <- chr.names
odd.names[evens] <- ""

kpAddChromosomeNames(kp, chr.names = odd.names)
kpAddChromosomeNames(kp, chr.names = even.names, yoffset = -10)

You can also modify the names vector to remove "chr", etc... If you have any problem with this, please ask

In any case, I'll log the request for the staggered option for future developments :)

Thanks!