Gviz: How to control `grid` parameter and how to add horizontal lines with different colors to DataTrack?
1
3
Entering edit mode
@ezgi-karaesmen-11468
Last seen 6.3 years ago

Hi,

I'm using gviz to plot some GWAS data and my DataTrack is showing the association p-values of SNPs  for a certain genomic region, which is a pretty basic dot plot. I would like to show certain significance levels on my plot, and add several horizontal lines with different colors (or at least different colors than my dots...). I tried abline parameter in the DataTrack function but didn't really help. Is there another way to add horizontal lines?

Also I want to add some horizontal grid lines to my DataTrack which is relatively easy to do by setting grid=T, v=0, h=10 , where the integer controls the number of lines, but how can I control the coordinates of these lines?

Thanks!

gviz • 2.7k views
ADD COMMENT
2
Entering edit mode
li lilingdu ▴ 450
@li-lilingdu-1884
Last seen 6.6 years ago

Solution I considered is to add grid grills firstly and then modify their positions , following is the code, but another problem occur:

library(Gviz)

########using the example data contained in Gviz 
data(twoGroups)
dat<-resize(twoGroups,width=1)
dat<-dat[,'control']
dTrack <- DataTrack(dat, name = "uniform")
plotTracks(dTrack,grid=T,col.grid='gray',v=0,h=5)

###############make some modification of the horizon grid lines
grid.edit('.grid.h.panel..',y0=unit(c(-5,0,5),'native'),y1=unit(c(-5,0,5),'native'),gp=gpar(col=c('red','green','blue')))

However, the horizon lines (the 5 and -5 horizon line)was not correctly placed. Is this due to the viewport where the points and grill lines were really plotted was not pushed ? And how can I push the viewport correctly? It looks like I can't get this information from the grid grill grob (in fact segmentsGrob):

grid.get('.grid.h.panel..')$vp
any advice? thanks!

ADD COMMENT
1
Entering edit mode

Just for add of horizon lines:

plotTracks(dTrack,baseline=c(-5,0,5),col.baseline=c('red','green','blue'))
ADD REPLY
0
Entering edit mode

But it will be greater to list/get the viewports and even the correspondence of grobs and viewports in the plot, so more detailed and flexible control of the plot can be achieved. 

For task such as http://stackoverflow.com/questions/25494125/plotting-arbitrary-lines-at-gviz-plottracks would be possible to do using grid low-level functions.

ADD REPLY
0
Entering edit mode

Gviz does not expose that much of the grid underlining, and frankly I don't think that this would be particularly useful. There are several nested viewports that make up a typical Gviz plot, and just the thought of an API to expose that make me shiver...

You can get full control over the main graph viewport using a combination of OverlayTrack and CustomTrack objects:

st <- c(2000000, 2070000, 2100000, 2160000)

ed <- c(2050000, 2130000, 2150000, 2170000)

str <- c("-", "+", "-", "-")

gr <- c("Group1","Group2","Group1", "Group3")

annTrack <- AnnotationTrack(start=st, end=ed, strand=str, chromosome=7, genome="hg19", feature="test", group=gr, id=paste("annTrack item", 1:4), name="generic annotation", stacking="squish")

library(lattice)

ct <- CustomTrack(plottingFunction=function(GdObject, prepare){ if(!prepare) panel.grid(); return(GdObject)})

plotTracks(OverlayTrack(trackList=list(annTrack, ct)))

 

 

 

ADD REPLY

Login before adding your answer.

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