how can I add a label for granges using the geom_rect ?
1
0
Entering edit mode
潘晓光 • 0
@717d0f02
Last seen 24 months ago
China

geom_rect(data,..., xlab, ylab, main,
          facets = NULL, stat = c("stepping", "identity"),
          rect.height = NULL,
          group.selfish = TRUE)

for the GRanges object, the function didn't give the parameter to plot names for each Grange when using stat_stepping. But how can I know which rect are from which Grange?

ggbio • 1.2k views
ADD COMMENT
1
Entering edit mode
@james-w-macdonald-5106
Last seen 57 minutes ago
United States

Labels seem to be problematic if you have many ranges. Color might be better?

## this is just the example GRanges object
> set.seed(1)
> N <- 100
> gr <- GRanges(seqnames = sample(c("chr1", "chr2", "chr3"),
+                                 size = N, replace = TRUE),
+               IRanges(start = sample(1:300, size = N, replace = TRUE),
+                       width = sample(70:75, size = N,replace = TRUE)),
+               strand = sample(c("+", "-"), size = N, replace = TRUE),
+               value = rnorm(N, 10, 3), score = rnorm(N, 100, 30),
+               sample = sample(c("Normal", "Tumor"),
+                               size = N, replace = TRUE),
+               pair = sample(letters, size = N,
+                             replace = TRUE))
> seqlengths(gr) <- c(400, 1000, 500)
> autoplot(gr, aes(fill = sample))

Seems like a reasonable compromise. But these are just ggplot objects, so you could use e.g., ggrepel to make labels if you really wanted to.

ADD COMMENT
0
Entering edit mode

Thank you so much for your comment. As you say, if I have more than 100 ranges, the color will not be as easy to recognize as the label. But at the most time ,label will be more usefull beacuse we can save the picture as PDF and modify it in Adobe Illustrate.

ADD REPLY
0
Entering edit mode

For the ggreprl, do you know how to add a label using it? If we use geom_label or geom_text, we need to know the X and Y, but ggbio will randomly make a Y value for each GRange. I can't have X and Y for the label.

ADD REPLY
0
Entering edit mode

It uses biovizBase:::addStepping under the hood if you use the 'stepping ' argument. It's possible you could use that on the front end and use 'identity' instead.

ADD REPLY
0
Entering edit mode

Thank you so much, I will try it

ADD REPLY

Login before adding your answer.

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