facet_grid for two datasets

93 views
Skip to first unread message

Hermann Norpois

unread,
Oct 5, 2012, 3:59:47 PM10/5/12
to ggp...@googlegroups.com
Dear list,

I would like to combine two datasets via facet_grid. Both data sets have the same x axis (chromosomal coordinates) and the y axis should refer to signals from different experiments (array and precipitation experiments). I wish to have two coordinate systems, one directy above the other (the x axis parallel and identical in terms of sizing). I feel that facet_grid should work (see below - marked with ????) but actually I do not know how to vary the syntay. Could anybody help me?

adata: array data with transcript start sites on chromosome 11 (transcript.start) and the foldchanges.
pdata: histone precipitation data from chromosome 11, start and end are the precipitated DNA coordinates and peak ... the peak.

> dput (adata)
structure(list(transcript.start = c(3125936L, 3142378L, 3187355L,
3189052L, 3193421L, 3193421L), foldchange = c(0.8656, 0.7751,
0.8779, 0.9557, 1.0108, 0.9307)), .Names = c("transcript.start",
"foldchange"), row.names = c(NA, 6L), class = "data.frame")

> dput (pdata)
structure(list(start = c(5390998L, 11088023L, 11867948L, 11940898L,
12367448L, 12376673L), end = c(5391923L, 11088523L, 11868673L,
11941848L, 12368073L, 12377048L), peak = c(8L, 7L, 8L, 8L, 12L,
7L)), .Names = c("start", "end", "peak"), row.names = c(NA, 6L
), class = "data.frame")


This is my idea. But: What is the correct syntax for facet_grid?

> p <- ggplot (adata, aes (x=transcript.start, y=foldchange))+ geom_point() + geom_segment (data=pdata, aes (x=start, xend=end, yend=0, y=peak), color="red")

> p+facet_grid()  ?????

Thanks
Hermann

Brandon Hurr

unread,
Oct 5, 2012, 4:48:15 PM10/5/12
to Hermann Norpois, ggp...@googlegroups.com
Try this... Not perfect, but maybe it's close enough for what you want it to do. 

require(plyr)
names(adata)[1]<-"start"
#names(pdata)[3]<-"foldchange"
adata$type<-"adata"
pdata$type<-"pdata"


ndata<-rbind.fill(adata, pdata)

ggplot(data=ndata)+
geom_point(aes(x=start, y=foldchange))+
geom_segment(aes(x=start, xend=end, yend=0, y=peak), color="red")+
facet_grid(type~., scales="free_y")




Hermann

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages