Gradient dotplot
0
0
Entering edit mode
@78ca6878
Last seen 3.1 years ago
Denmark

I've been playing around with GViz, but I cannot for the life of me figure out how to make my plot. I would like to make my datatrack a dotplot, colored by a gradient based on a different variable. Basically:

ggplot(fst_snpchr10_51556910,aes(x=POS,y=Z_FST))+geom_point(aes(color=R2),  size=1)

I just can't figure out how to do that with GViz and I would really like to have the annotationtrack.

Thanks!

Gviz • 1.5k views
ADD COMMENT
1
Entering edit mode

It is not possible to color the points in a DataTrack based on a continuous variable at the moment.

ADD REPLY
0
Entering edit mode

But this a bit "hackish" solution might work for you. It takes advantage of groups which are defined as separate columns.

library(RColorBrewer)
library(Gviz)

set.seed(100)
gr <- GRanges("chr1", IRanges(seq(1,5000,5), width=1), strand="+",
              val=rnorm(1000, 0, 5))
# cut values according to breaks
rr <- c(-20, seq(-12,12,length.out=9), 20)
gr$fac <- cut(gr$val, breaks=rr, include.lowest=TRUE)

# build new mcols with columns representing groups
temp <- vapply(levels(gr$fac), function(lev, val=gr$val, fac=gr$fac) {
    ifelse(fac==lev, val, NA)}, FUN.VALUE=numeric(length(gr))) 
mcols(gr) <- temp

# grouping (order of levels is important) and plot
grps <- factor(colnames(mcols(gr)), levels=colnames(mcols(gr)))
plotTracks(DataTrack(gr), col=rev(brewer.pal(11, "RdBu")[-6]), groups=grps)
ADD REPLY
0
Entering edit mode

That's smart, I'm a bit worried that it'll break my computer if I get enough levels in there to make me happy, but I'll give it a try.

ADD REPLY

Login before adding your answer.

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