karyoploteR icon indicating copy to clipboard operation
karyoploteR copied to clipboard

kpPlotDensity ymax

Open gbdias opened this issue 6 years ago • 5 comments

Hi,

I wanted my density plot to display only values up to a certain number. When I try to use the ymax parameter I still see density regions way above my plot ceiling, and actually overlapping the plots above (image below).

kp <- kpPlotDensity(kp, data = dataGR, window.size = 10000, border="black", col="#b3ffe099", ymax=2)
Screen Shot 2019-05-09 at 4 07 08 PM
  • When I add kpAxis to this plot I only see values of 0-1, despite the density values ranging from 1-86. (I checked the kp$latest.plot$computed.values$density)
  • Is there a better way to put a cap on what density value is displayed on the plot?

Thanks

gbdias avatar May 09 '19 20:05 gbdias

Hi @gbdias

This is the expected behaviour. ymax willl tell kpPlotDensity to vertically scale the data so y=2 is at the top of the data panel, but it will not modify the data in any way, so if the density is over 2, the peaks will be higher than. In addition, kpAxis will always plot an axis from 0 to 1 unless you specify something else with ymin-ymax

An option would be to create two plots, the first one just to the density data and the second one to plot a modified version of the density data using kpArea.

library(karyoploteR)
#Example data
gr <- toGRanges(c("chr1:1-10e6", "chr1:2e6-8e6", "chr1:4e6-6e6", "chr1:5e6-20e6"))


kp <- plotKaryotype(zoom=toGRanges("chr1:1-30e6"))
kp <- kpPlotDensity(kp, gr)

#Get the data
windows <- kp$latest.plot$computed.values$windows
dens <- kp$latest.plot$computed.values$density

#Modify the density values
dens[dens>2] <- 2

#Create the valid plot
kp <- plotKaryotype(zoom=toGRanges("chr1:1-30e6"))
kpArea(kp, windows, y = dens, ymax=2)
kpAxis(kp, ymax=2)

In a more general case, if you don't need to modify the density, to plot the axis you should use

kpAxis(kp, ymax=kp$latest.plot$computed.values$max.density)

Hope this helps

Bernat

bernatgel avatar May 14 '19 12:05 bernatgel

Hi @bernatgel

  • Thanks for the tip.
  • Is there something similar that can be done for the kpPlotCoverage function? I don't see the kp$latest.plot variable when I use this function

gbdias avatar May 15 '19 18:05 gbdias

Hi again,

It was a problem in the code. I've now added a new "coverage" object to the kp returned by kpPlotCoverage so you can do the same you do with density.

The version 1.10.2 from release should be available in a couple of days in the Bioconductor repositories or you can install it from the RELEASE_3_9 branch in github

bernatgel avatar May 17 '19 07:05 bernatgel

Hi again @bernatgel,

I have a similar question as before but this time for the kpPlotBAMDensity function. I'm trying to make the plot axis match the BAM density plot but I'm now sure where to grab the ymax. I've tried kp$plot$ymax but that doesn't seem to be it. Is there a way to capture the ymax value for kpPlotBAMDensity?

Thanks

gbdias avatar Sep 04 '20 21:09 gbdias

Any update on this @bernatgel? I've the same problem as @gbdias. Please help

immuneAI avatar Dec 21 '21 01:12 immuneAI