databio / GenomicDistributions

Calculate and plot distributions of genomic ranges
http://code.databio.org/GenomicDistributions
Other
25 stars 10 forks source link

make an option to plot different datasets by different colors #180

Open kkupkova opened 2 years ago

kkupkova commented 2 years ago

Some functions currently don't offer the option to plot different datasets by different colors (plotFeatureDist, plotQTHist) and are written in a way that it would be impossible to add that option as another layer to the ggplot object.

rrashford commented 2 years ago

Hi!

I am interested in this issue. Is there a way to change the colors for plotting on these three functions? plotChromBins plotExpectedPartitions plotPartitions

All the best,

kkupkova commented 2 years ago

Hi! The output of the plot function is always ggplot object, so you can always add another layer or change the color setting. I am giving here examples for the three functions you are interested in - for single region set or multiple region sets:

# upload queries
# single query
queryFile = system.file("extdata", "vistaEnhancers.bed.gz", package="GenomicDistributions")
query = rtracklayer::import(queryFile)

# query list
query2 = GenomicRanges::shift(query, 1e6)
queryList = GRangesList(vistaEnhancers=query, shifted=query2)

# 1) single region set - change color to red
# chromosome distribution
chrombins = calcChromBinsRef(query, "hg19")
p = plotChromBins(chrombins)
p$layers[[1]]$aes_params$fill =  'red'
p

# partition overlap
part = calcPartitionsRef(query, "hg19")
p = plotPartitions(part)
p$layers[[1]]$aes_params$fill =  'red'
p

# expected paritions
ePart = calcExpectedPartitionsRef(query, "hg19")
p = plotExpectedPartitions(ePart)
p$layers[[1]]$aes_params$fill =  'red'
p

# 2) multiple region sets - change color to red and blue
chrombins = calcChromBinsRef(queryList, "hg19")
plotChromBins(chrombins) + 
  scale_fill_manual(values = c("red", "blue")) +
  scale_color_manual(values = c("red", "blue"))

# partition overlap
part = calcPartitionsRef(queryList, "hg19")
plotPartitions(part)+ 
  scale_fill_manual(values = c("red", "blue")) 

# expected paritions
ePart = calcExpectedPartitionsRef(queryList, "hg19")
plotExpectedPartitions(ePart)+ 
  scale_fill_manual(values = c("red", "blue")) 

These examples are applicable to all of the other plotting functions. Hope this helps!

rrashford commented 2 years ago

Yes! This was super helpful. Thank you!