bernatgel / karyoploteR

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

How to add x axis title #111

Closed xiucz closed 2 years ago

xiucz commented 2 years ago

Hi ,

After search the biostars and the document, I still cann't find how add x axis title. Can you show me a example?

Thank you.

bernatgel commented 2 years ago

Hi xiucz,

The idea with these plots is that you don't need to add an x axis label, since it's the natural positioning on the genome.

If you want to add a label, though, you can use the text base function giving x=0.5 (to center it horizontally) and y adjusted depending on the bottom margin of your plot (default is 100 or 30 (depending on the plot.type), you can find the default value for each plot type with getDefaultPlotParams). You'll need soma manual adjustment, but it should work.

Hope this helps. If you need more guidance, just ask :)

Bernat

xiucz commented 2 years ago

@bernatgel My code is here:

plot.params <- getDefaultPlotParams(plot.type=1)
plot.params$ideogramheight <- 30
kp <- plotKaryotype(chromosomes=chrom, plot.params=plot.params)
kpAddCytobandLabels(kp, cex=0.5, srt=90)
kpAddBaseNumbers(kp, add.units = T, cex = 0.5, tick.dist=50000000)

kpAxis(kp, ymin=0, ymax=6, cex=0.5, numticks=7, r0=0, r1=0.3)

#then, add the main title 
kpText(kp, chr=chrom, x=chrom.len/2, y=0.4, labels="CNV result")

I use kpText here rather than kpAddMainTitle, because kpAddMainTitle option keeps the title far away from main plot. I tried getDefaultPlotParams, but it not worked well.

Now, let's plot x axis title, because add.units = T lead to overlapped "Mb"( "M" and "b")

image.

kpText(kp, chr=chrom, x=chrom.len/2, y=????, labels="Chrom position(Mb)")

But how do I set the y option to plot under the x axis?

Thank you. xiucz