1
$\begingroup$

I have a GRanges object with metadata that I want to plot. Many of the online tutorials which manipulate these GRanges for plotting show how to plot the main columns (chromosome,start/end,strand) but nothing to plot the metadata as a function of the position in each row.

How precisely should I do this? Ideally, I would like to plot metadata from multiple GRanges objects on the same plot to compare them.

EDIT (following comment):

GRanges object with 6 ranges and 140 metadata columns:
      seqnames        ranges strand |
         <Rle>     <IRanges>  <Rle> |
  [1]     chr1 100000-199999      * |
  [2]     chr1 400000-499999      * |
  [3]     chr1 600000-699999      * |
  [4]     chr1 700000-799999      * |
  [5]     chr1 800000-899999      * |
  [6]     chr1 900000-999999      * |
                  eigen   domain         arm
              <numeric> <factor> <character>
  [1] -1.62475825405065     open          1p
  [2] -1.62475825405065     open          1p
  [3] -1.62475825405065     open          1p
  [4] -1.62475825405065     open          1p
  [5] -1.63354915136132     open          1p
  [6]  -1.6322733358426     open          1p
      exon.fraction       gc     short      long
          <numeric> <matrix> <numeric> <numeric>
  [1]       0.02968  0.45815         0         0
  [2]       0.04305  0.40192         0         0
  [3]       0.00959  0.42091         0         0
  [4]       0.04593  0.43337         0         1
  [5]       0.02425  0.44822         2         1
  [6]       0.16977  0.62123        27        56
         nfrags             ratio   short.corrected
      <numeric>         <numeric>         <numeric>
  [1]         0               NaN              <NA>
  [2]         0               NaN              <NA>
  [3]         0               NaN              <NA>
  [4]         1                 0 -3.50822623240367
  [5]         3                 2  2.81796238367926
  [6]        83 0.482142857142857  39.8824095079959
...

My question regards plotting a column like eigen as a function of the position (given by seqnames and ranges)

$\endgroup$
1
  • $\begingroup$ Can you show us head(., 10) for a few of the datasets so we can understand what you're trying to plot? $\endgroup$
    – Ram RS
    Commented Jun 17, 2020 at 13:58

1 Answer 1

1
$\begingroup$

You can access the data.frame just using $. All of them can be accessed using values() . Something like this:

library(GenomicRanges)
gr = GRanges(seqnames=1,IRanges(start=1:10,width=1))
values(gr) = data.frame(eigen=rnorm(10),ratio=runif(10))

plot(start(gr),gr$eigen)

or

plot(start(gr),values(gr)$eigen)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.