ggbio
ggbio copied to clipboard
Plotting segments out of Granges object
Hello
I have a Granges object that is like this :
GRanges with 6 ranges and 6 metadata columns:
seqnames ranges strand | score id highlight
<Rle> <IRanges> <Rle> | <numeric> <factor> <logical>
[1] 1 [ 4793, 227744] * | -0.17 DAH115 FALSE
[2] 1 [ 522302, 558478] * | -0.03 DAH115 FALSE
[3] 1 [ 695745, 978366] * | -0.06 DAH115 FALSE
[4] 1 [1055159, 1231946] * | 0.24 DAH115 FALSE
[5] 1 [1239050, 1589751] * | -0.05 DAH115 FALSE
[6] 1 [1593026, 1610764] * | 0.25 DAH115 FALSE
I am basically plotting a bar plot with x : genome coordinates, and y : score
I would like to know how can I add segment (Start and End) would be the IRanges that correspond to a certain value of the object.
Example : if values(myobject)$id = DAH115 plot the correspondant segments on top of the final histogram.
I think we can use geom_segment but I am not sure how to extract the ranges
Thanks
Hi
I am not sure what you trying to do , are you trying to show segment on top of it or want to combine range for DAH115 and show it on top? is that something like example below? [image: Inline image 1] library(GenomicRanges)
simul
set.seed(123) gr.b <- GRanges(seqnames = "chr1", IRanges(start = seq(1, 100, by = 10), width = sample(4:9, size = 10, replace = TRUE)), score = rnorm(10, 10, 3), value = runif(10, 1, 100), id = rep(1:4, each = 3, len = 10)) gr.b
bar
ggplot(gr.b) + geom_bar(aes(fill = value)) + geom_segment(stat = "identity", aes(y = score + 2))
On Tue, Mar 25, 2014 at 7:45 PM, Radhouane Aniba [email protected]:
Hello
I have a Granges object that is like this :
GRanges with 6 ranges and 6 metadata columns: seqnames ranges strand | score id highlight <Rle> <IRanges> <Rle> |
[1] 1 [ 4793, 227744] * | -0.17 DAH115 FALSE [2] 1 [ 522302, 558478] * | -0.03 DAH115 FALSE [3] 1 [ 695745, 978366] * | -0.06 DAH115 FALSE [4] 1 [1055159, 1231946] * | 0.24 DAH115 FALSE [5] 1 [1239050, 1589751] * | -0.05 DAH115 FALSE [6] 1 [1593026, 1610764] * | 0.25 DAH115 FALSE I am basically plotting a bar plot with x : genome coordinates, and y : score
I would like to know how can I add segment (Start and End) would be the IRanges that correspond to a certain value of the object.
Example : if values(myobject)$id = DAH115 plot the correspondant segments on top of the final histogram.
I think we can use geom_segment but I am not sure how to extract the ranges
Thanks
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51 .
Thanks tengfei , I don't see the image attached in your comment.
Basically I have a bar plot over the human genome on x axis
I would like to plot segment corresponding on some ranges (start - end ) that corresponds to a given id (see the Grange object I provided)
basically from chr1 to Y we will see some small segments (horizontal lines) on the plot
is that possible ?
Is it possible to add karyotypes on the x axis ?
Hi
Can you try something like this, in plotGrandLinear function, you can pass a highlight.gr argument to highlight some color, you pass your GRanges to that argument, any points that is overlapped with it will be highlighted, you can change highlight color too. To use label, use names()
gro <- GRanges(c("1", "11"), IRanges(c(100, 2e6), width = 5e7)) names(gro) <- c("group1", "group2") plotGrandLinear(gr.snp, aes(y = pvalue), highlight.gr = gro)
is this close to some thing you want?
To add something like segment on top, I need to add support, and if you come across any bug, please let me know.
[image: Inline image 1]
On Wed, Mar 26, 2014 at 2:59 PM, Radhouane Aniba [email protected]:
Thanks tengfei , I don't see the image attached in your comment.
Basically I have a bar plot over the human genome on x axis
https://camo.githubusercontent.com/df89d5d862b4757791afd4602c11fb6d105db45d/687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d57515a5f47475f76386a732f546258542d65554f6271492f41414141414141414c71412f6e7849596d5f435f7235492f73313630302f323031312d30342d31392532304747442532306d616e68617474616e322e706e67
I would like to plot segment corresponding on some ranges (start - end ) that corresponds to a given id (see the Grange object I provided)
basically from chr1 to Y we will see some small segments (horizontal lines) on the plot
is that possible ?
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38725237 .
Not really :) but thanks, actually I am using autoplot not plotGrandLinear
One last attempt I am trying to do is to plot boundaries for chromosomes (actually all these questions because I would like to see clear delimitations of chromosomes, but not using colors, vertical lines may be ? )
Thanks
Rad
this actually was asked in bioc list two days ago, the current workaround is attached below, in next release we will have a parameter building in to do this.
p <- plotGrandLinear(gr.snp, aes(y = pvalue), color = c("#7fc97f", "#fdc086")) vline.df <- p@ggpplot$data vline.df <- do.call(rbind, by(vline.df, vline.df$seqnames, function(dd){ data.frame(start = min(dd$start), end = max(dd$end)) }))
compute gap
gap <- (vline.df$start[-1] + vline.df$end[-nrow(vline.df)])/2 p + geom_vline(xintercept = gap, alpha = 0.5, color = 'gray70') + theme(panel.grid = element_blank())
[image: Inline image 1]
On Fri, Mar 28, 2014 at 12:29 PM, Radhouane Aniba [email protected]:
Not really :) but thanks, actually I am using autoplot not plotGrandLinear
One last attempt I am trying to do is to plot boundaries for chromosomes (actually all these questions because I would like to see clear delimitations of chromosomes, but not using colors, vertical lines may be ? )
Thanks
Rad
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38939149 .
and you could use
"space.skip" parameters
in plotGrandLinear() function to add more space between chrom and one another key, please assign seqlength to your granges object, otherwise, the chromosome space is not accurate, will be estimated from data.
plotGrandLinear() has more control over this type of graphics, I will work on some of your feature request in devel
thanks a lot
Tengfei
On Fri, Mar 28, 2014 at 12:29 PM, Radhouane Aniba [email protected]:
Not really :) but thanks, actually I am using autoplot not plotGrandLinear
One last attempt I am trying to do is to plot boundaries for chromosomes (actually all these questions because I would like to see clear delimitations of chromosomes, but not using colors, vertical lines may be ? )
Thanks
Rad
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38939149 .
Great I will try these. Is there a way to convert a genomic coordinate to map the new coordinates on a manhattan plot ?
if you mean how to add-on more data into manhattan plot coordinate easily, man this is what I am struggling with right now ... and trying to finish it by April ... ;) I will keep you updated
On Fri, Mar 28, 2014 at 1:35 PM, Radhouane Aniba [email protected]:
Great I will try these. Is there a way to convert a genomic coordinate to map the new coordinates on a manhattan plot ?
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38946721 .
:+1: :) Great work
but you should have that though, if I use hg19 with chromosomes coordinates, I am interested in the mapping to the x axis (new coordinates) after applying coord="genome"
actually this conversation is helpful for me to understand the your case, is your request more like:
adding data layer by layer on coordinate "genome"?
something like
autoplot(data, ... coord = "genome") + geom_rect(newdata, aes() ) + more ...
or
ggbio() + geom_rect() + geom_point() + coord_genome()?
On Fri, Mar 28, 2014 at 1:42 PM, Radhouane Aniba [email protected]:
but you should have that though, if I use hg19 with chromosomes coordinates, I am interested in the mapping to the x axis (new coordinates) after applying coord="genome"
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38947538 .
Exactly the first
autoplot(data, ... coord = "genome") + geom_rect(newdata, aes() ) + more
Got it, thanks, I will let you know when I implement it in the devel, I am trying to catch up with this release of bioc.
On Fri, Mar 28, 2014 at 1:52 PM, Radhouane Aniba [email protected]:
Exactly the first autoplot(data, ... coord = "genome") + geom_rect(newdata, aes() ) + more
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/51#issuecomment-38948654 .
Hi Tengfei,
Is there any progress on this issue?
I would also like to create a plot with SNP p-values, genes, and other scores in different tracks, similar to LocusZoom. I would like to be able to run a command
p.ideo <- ggbio::Ideogram(genome = "hg19")
p.txdb <- ggbio::autoplot(Homo.sapiens)
p.gwas <- ggbio::plotGrandLinear(gr.gwas, aes(y = pvalue))
p.gene_score <- ggbio:: autoplot(gene_score, aes(y = score), coord = "genome", geom = "bar")
final_plot <- tracks(p.ideo,
gene_score = p.gene_score,
gwas = p.gwas,
gene = p.txdb) +
xlim(range(genesymbol[c("HAND2")]
Thank you, -Jonathan