How to add a color legend to plotKaryotype and kpPlotRegions ?
1
1
Entering edit mode
Aditya ▴ 160
@aditya-7667
Last seen 2.5 years ago
Germany

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 • 3.5k views
ADD COMMENT
3
Entering edit mode
bernatgel ▴ 150
@bernatgel-7226
Last seen 16 days ago
Spain

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 343 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6