Gviz change color of groups
2
0
Entering edit mode
gamma.jian ▴ 10
@franceschinigianmarco-16472
Last seen 11 weeks ago
Switzerland

I am trying to plot two groups within a single track using Gviz.


sample_tissue = DataTrack(data = all_beta, start = sg_tissue$start,
                            end = sg_tissue$end, chromosome = chr, 
genome = gen, name = "Tissue Beta",
                            groups = tissue_all_class, degree = .8, family = c("symmetric", "gaussian"), evaluation = 100,
                            background.title = "brown", type = c("smooth", "p"), cex.legend = 0.7,     
                            cex.title = .6, cex.axis = .6, ylim = c(0,100))

I would like to change default colours (magenta and cyan), is it possible?

I've read the manual and it describes a step involving the use of feature, and the possibility of overwriting the default fill color, but I can't sort it out.

Moreover, I would like to know if it is possible to set different alphas for different elements in the track. In this case, I would like to have alpha = 1 for the "smooth" and alpha=0.5 for the "p", for example.

Thank you for your help,

gviz-package gviz • 4.1k views
ADD COMMENT
1
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.2 years ago
Switzerland

Have you tried the obvious?

dat <- matrix(runif(400), nrow=4)
dtTrack <- DataTrack(start=seq(1,1000, len=100), width=10, data=dat, chromosome=1, genome="mm9", name="random data")    
library(GenomicRanges)
gr <- GRanges(seqnames="chr1", ranges=IRanges(seq(1,1000, len=100), width=10))
values(gr) <- t(dat)
dtTrack <- DataTrack(range=gr, genome="mm9", name="random data", groups=c(1,1,2,2), col=c("red", "orange"), degree = .8, family = c("symmetric", "gaussian"))
plotTracks(dtTrack, type=c("smooth", "p"))​

For different alpha settings you will indeed need to use the more flexible OverlayTrack functionality.

 

 

 

ADD COMMENT
0
Entering edit mode

Thank you for your answer, I don't know how I managed to miss this very basic attempt

ADD REPLY
0
Entering edit mode

What if there were two DataTracks with data containing the same groups but appearing in a different order (because it is different data) and I want to have the groups to be the same colours? Is there a way to force colours to specific groups?

Using the above example I guess it would be equivalent to:

`dtTrack1 <- DataTrack(range=gr, genome="mm9", name="random data", groups=c(1,1,2,2), col=c("red", "orange"), degree = .8, family = c("symmetric", "gaussian"))

dtTrack2 <- DataTrack(range=gr, genome="mm9", name="random data", groups=c(2,1,1,2), col=c("red", "orange"), degree = .8, family = c("symmetric", "gaussian"))

plotTracks(dtTrack1, dtTrack2, type=c("smooth", "p"))`

And yes - I know that 'col=c("orange", "red")' would solve it with this example but I have many more groups, so this is not what I am after.

Thank you.

ADD REPLY
1
Entering edit mode

Hi Kristian,

You can achieve it with defining group as a factor.

Best Robert

library(Gviz)

set.seed(123)
gr <- GRanges("chr1", IRanges(sort(sample(999, 100)), width=1))
mcols(gr) <- matrix(runif(400), ncol=4)

dtTrack1 <- DataTrack(range=gr, genome="mm9", name="random data", groups=factor(c(1,1,2,2), levels=c(1,2)), col=c("red", "orange"), degree = .8, family = c("symmetric", "gaussian"))

dtTrack2 <- DataTrack(range=gr, genome="mm9", name="random data", groups=factor(c(2,1,1,2), levels=c(1,2)), col=c("red", "orange"), degree = .8, family = c("symmetric", "gaussian"))

plotTracks(list(dtTrack1, dtTrack2), type=c("smooth", "p"))
ADD REPLY
0
Entering edit mode

Thanks. It works when both levels and col are specified, but not if one of them is missing.

ADD REPLY
0
Entering edit mode
gamma.jian ▴ 10
@franceschinigianmarco-16472
Last seen 11 weeks ago
Switzerland

The best workaround I've found is to use overalyed tracks, plotting for each single track only one element, being points or line. In that way the color can be specified for each track. However I am still not able to set different alphas for overlaying tracks, probably because I'm missing something.

ADD COMMENT

Login before adding your answer.

Traffic: 362 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