ivanek / Gviz

This is the Gviz development repository. Gviz plots data and annotation information along genomic coordinates.
https://bioconductor.org/packages/Gviz/
Artistic License 2.0
75 stars 10 forks source link

groups factor in histogram/horizon datatrack doesnt change its color #77

Closed AmhedVargas closed 1 year ago

AmhedVargas commented 1 year ago

Hello,

I've been struggling to understand an error that makes impossible to overlay histogram tracks without confusing the data. In specific, I have not been able to change the color of data tracks based on the factor assigned in their group. If I use line or points plot the factor grouping works, e.g.:

library(Gviz)
gr1 = GRanges(seqnames = "chr1",ranges = IRanges(start = seq(1,100,by = 10),width = 5))

dt1 <- DataTrack(
  range = gr1,
  data = 1:10,
  alpha.title = 1, 
  groups = factor("forward",levels = c("forward", "reverse")),
  type = c("p"),
  name = "forward only"
)

dt2 <- DataTrack(
  range = GenomicRanges::shift(gr1,3),
  data = 10:1 + 89,
  alpha.title = 1, 
  groups = factor("reverse",levels = c("forward", "reverse")),
  type = c("p"),
  name = "reverse only"
)

plotTracks(list(dt1,dt2))

image

But not if it's an histogram, e.g.:

dt1 <- DataTrack(
  range = gr1,
  data = 1:10,
  alpha.title = 1, 
  groups = factor("forward",levels = c("forward", "reverse")),
  type = c("histogram"),
  name = "forward only"
)

dt2 <- DataTrack(
  range = GenomicRanges::shift(gr1,3),
  data = 10:1 + 89,
  alpha.title = 1, 
  groups = factor("reverse",levels = c("forward", "reverse")),
  type = c("histogram"),
  name = "reverse only"
)

plotTracks(list(dt1,dt2))

image

I noticed that on an original version it seemed to be working as intended (as shown in a much older bug): https://github.com/ivanek/Gviz/issues/1

However, even using the same code, I'm not able to make the same figure. At first, I thought it could be due to the version of Gviz so I moved to R 4.3 and installed the most recent version of Gviz, however the issue remains. Changing OS between windows and Ubuntu didn't help either.

Finally, I also noticed that in the vignette of Gviz, the grouping worked for the overlay with points plot but not the one of the histogram:

https://bioconductor.org/packages/release/bioc/vignettes/Gviz/inst/doc/Gviz.html#62_Overlays

So perhaps this error have been present in a while. For now, I tried to alter the color schema using displayPars, however I am not able to have a proper legend.

Thanks for any info or work around this issue

Cheers

ivanek commented 1 year ago

Hi @AmhedVargas,

Thanks for spotting it. I have fix 82fb103 it and pushed the update to Bioc 3.17 (version 1.43.3 in devel branch) but I am not sure if that would be directly reflected in first release 1.44.0. If not I back-port it there.

AmhedVargas commented 1 year ago

Hey @ivanek,

Thanks for your prompt reply and fix. I'll be updating Gviz much later then. For now, I solved the problem by changing the colors in the displayPars and then overlaying multiple times the plot with the right legend. Thanks again.