colByRegion {karyoploteR} | R Documentation |
Given a set of data elements, return a color for each one based on whether they overlap a given set of regions. This might be useful, for example, to set a different color for data points overlapping a certain region of interest.
colByRegion(data, regions, colors=NULL, default.col="black")
data |
Either a vector of characters or a GRanges object |
regions |
(GRanges or equivalent) A set of regions where the color will be modified. Internally it will be converted into a Genomic Ranges object by |
colors |
(color) The colors to be used for each region. The content will be recycled if needed. If NULL, the colors are assumed to be available in the regions object. (defaults to NULL) |
default.col |
The default color to return for data elements not overlapping the regions. (defaults to "black") |
Given a set of data elements, return a color for each one based on whether
they overlap a given set of regions. The colors might be different for each
region and can be specified either in the regions object itself or in
a separate colors
parameter. If specified in colors
, the values
will be recycled as needed.
A vector of colors
data <- toGRanges("chr1", c(1e6*1:245), c(1e6*1:245)+10) data$y <- rnorm(n = length(data), mean = 0.5, sd = 0.15) regions <- toGRanges(c("chr1:10e6-20e6", "chr1:100e6-150e6")) regions$col <- c("red", "blue") kp <- plotKaryotype(chromosomes="chr1") kpPoints(kp, data=data, r0=0, r1=0.2) kpPoints(kp, data=data, r0=0.2, r1=0.4, col=colByRegion(data, regions = regions) ) kpText(kp, data=data, r0=0.4, r1=0.6, col=colByRegion(data, regions = regions), label="A", cex=0.5 ) kpBars(kp, data=data, y0=0, y1=data$y, r0=0.6, r1=0.8, border=colByRegion(data, regions = regions)) #It might not work wor objects where R expects a single color such as lines. Segments should be used instead kpLines(kp, data=data, r0=0.8, r1=1, col=colByRegion(data, regions = regions) ) kp <- plotKaryotype(chromosomes="chr1") kpPoints(kp, data=data, r0=0, r1=0.25) kpPoints(kp, data=data, r0=0.25, r1=0.5, col=colByRegion(data, regions = regions, colors="green") ) kpText(kp, data=data, r0=0.5, r1=0.75, col=colByRegion(data, regions = regions, color=c("gray", "gold")), label="A", cex=0.5 ) kpBars(kp, data=data, y0=0, y1=data$y, r0=0.75, r1=1, border=colByRegion(data, regions = regions))