0

I am trying to add gene labels to my plot that renders genomic segments using the ggbio package.

I am using the autoplot() function and pass in a GenomicRanges object. The GRange object has a column of metadata labels that I wish to appear on the generated plot on top of each graphed segment.

The question: How to add labels to the ggbio/ggplot2 plot from a metadata column?

My code is as follows, without labels and with g as a GenomicRanges object.

autoplot(g)
  • 1
    What is your question? – Tot Zam Jul 07 '15 at 02:08
  • I apologize if it was unclear. I have no idea how to add labels to individual genes with ggplot2 and ggbio so I was asking how the labels can be added. – Abby McKenzie Jul 07 '15 at 02:09
  • 3
    To make it easier to help you, you should provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) with sample input data and the code you are using to make your plot so we can run the code to see what you are seeing. Try to be as clear/specific as possible about what your desired result is. – MrFlick Jul 07 '15 at 02:43
  • By `gene labels` do you mean `HUGO Gene Symbol` ? – zx8754 Jul 07 '15 at 07:41
  • Example in ggbio manual section [2.2.2 Make gene model from OrganismDb object](http://www.bioconductor.org/packages/release/bioc/vignettes/ggbio/inst/doc/ggbio.pdf) works fine for me. – zx8754 Jul 07 '15 at 07:51

1 Answers1

0

As suggested before by user zx8754 I would follow the ggbio manual, but focus on section 2.2.5 Make gene model from GRangesList object.

Basically, the answer to your question about how to add labels to the ggbio plot from a metadata column would be to split the granges object based on the metadata column and use the autoplot function with this named grangeslist. The trick here is to add an extra column type="exon" to the granges object beforehand to mimic the gene/transcript model structure.

library(ggbio)
library(GenomicRanges)

g <- GRanges(seqnames = "chr1",
             ranges = c("100-150","150-200"), 
             strand = c("+","-"),
             group = c("A","B"),
             type = "exon")
autoplot(g)

grl <- split(g, g$group)
autoplot(grl)
#> Constructing graphics...

Created on 2021-02-08 by the reprex package (v1.0.0)

Alex
  • 106
  • 5