Question: How to add a color legend to plotKaryotype and kpPlotRegions ?
1
gravatar for Aditya
6 weeks ago by
Aditya120
Germany
Aditya120 wrote:

karyoploteR::plotKaryotype is great and works fine - thank you, Bernat :-) :

kp <- karyoploteR::plotKaryotype('mm10')
granges1 <- GenomicRanges::GRanges(c('chr1', 'chr2'), c('100-200', '100-200'))
granges2 <- GenomicRanges::GRanges(c('chr3', 'chr4'), c('100-200', '100-200'))
karyoploteR::kpPlotRegions(kp, granges1, col = "red")
karyoploteR::kpPlotRegions(kp, granges2, col = "green")

But how do I add a color legend (explaining what green and red set are)?

karyoploter • 128 views
ADD COMMENTlink modified 6 weeks ago by bernatgel120 • written 6 weeks ago by Aditya120
Answer: How to add a color legend to plotKaryotype and kpPlotRegions ?
2
gravatar for bernatgel
6 weeks ago by
bernatgel120
Spain
bernatgel120 wrote:

Hi Aditya,

You can use legend as you would use with any other plot.

kp <- karyoploteR::plotKaryotype('mm10')
granges1 <- GenomicRanges::GRanges(c('chr1', 'chr2'), c('100-200', '100-200'))
granges2 <- GenomicRanges::GRanges(c('chr3', 'chr4'), c('100-200', '100-200'))
karyoploteR::kpPlotRegions(kp, granges1, col = "red")
karyoploteR::kpPlotRegions(kp, granges2, col = "green")

legend(x = "bottomright", fill = c("red", "green"), legend = c("Ranges1", "Ranges2"))

That will give you something like this

enter image description here

I usually prefer them as a single line below the plot as in this image, although that would require a bit more of fiddling with the positions.

enter image description here

ADD COMMENTlink written 6 weeks ago by bernatgel120

Thank you Bernat, for brushing up my rusty base graphics knowledge, and making this great package!

May I ask one more question? Is it possible to store the Karyoplot object in a variable and print it to a plot later? This works for ggplot2 and grid. I thought it doesn't for base graphics, but with Karyoplot you seem to have found a way around.

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by Aditya120

Hehe! glad you find it useful!

karyoploteR is pure base graphics and so it's not possible to store it in a variable to plot later. Actually, karyoploteR plays really bad with graphics composition packages such as grid or the base par(mfrow=(A,B)). This is something I'd like to improve in the future, but for now the combination of karyoplots with other plots must be done out of R.

ADD REPLYlink written 6 weeks ago by bernatgel120

Hi again,

I just found out you can use karyoploteR with grid, cowplot and patchwork using the package ggplotify.

You can find the code in this github issue.

enter image description here

ADD REPLYlink modified 5 weeks ago • written 5 weeks ago by bernatgel120

Oh, that's pretty cool indeed! Thanks for sharing.

ADD REPLYlink written 5 weeks ago by Aditya120
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 281 users visited in the last hour