set.seed(1)
N <- 100
require(GenomicRanges)
## ======================================================================
## simmulated GRanges
## ======================================================================
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))
## ======================================================================
## default
##
## ======================================================================
ggplot(gr) + geom_chevron()
## or
ggplot() + geom_chevron(gr)
## ======================================================================
## facetting and aesthetics
## ======================================================================
ggplot(gr) + geom_chevron(facets = sample ~ seqnames, aes(color = strand))
## ======================================================================
## stat:identity
## ======================================================================
ggplot(gr) + geom_chevron(stat = "identity", aes(y = value))
## ======================================================================
## stat:stepping
## ======================================================================
ggplot(gr) + geom_chevron(stat = "stepping", aes(group = pair))
## ======================================================================
## group.selfish controls when
## ======================================================================
ggplot(gr) + geom_chevron(stat = "stepping", aes(group = pair), group.selfish = FALSE,
xlab = "xlab", ylab = "ylab", main = "main")
p <- qplot(x = mpg, y = cyl, data = mtcars)
## ======================================================================
## offset
## ======================================================================
gr2 <- GRanges("chr1", IRanges(c(1, 10, 20), width = 5))
gr2.p <- gaps(gr2)
## resize to connect them
gr2.p <- resize(gr2.p, fix = "center", width = width(gr2.p)+2)
ggplot(gr2) + geom_rect() + geom_chevron(gr2.p)
## notice the rectangle height is 0.8
## offset = 0 just like a line
ggplot(gr2) + geom_rect() + geom_chevron(gr2.p, offset = 0)
## equal height
ggplot(gr2) + geom_rect() + geom_chevron(gr2.p, offset = 0.4)
## ======================================================================
## chevron.height
## ======================================================================
values(gr2.p)$score <- c(100, 200)
ggplot(gr2) + geom_rect() + geom_chevron(gr2.p, offset = "score")
## chevron.height
ggplot(gr2) + geom_rect() + geom_chevron(gr2.p, offset = "score",
chevron.height.rescale = c(0.4, 10))
Run the code above in your browser using DataLab