stat_aggregate {ggbio}  R Documentation 
Generates summaries on the specified windows
## S4 method for signature 'GRanges' stat_aggregate(data, ..., xlab, ylab, main, by, FUN, start = NULL, end = NULL, width = NULL, y = NULL, frequency = NULL, delta = NULL, simplify = TRUE, window = NULL, facets = NULL, type = c("mean", "median", "max", "min", "sum", "count", "identity"), geom = NULL)
data 
A 
xlab 
Label for x 
ylab 
Label for y 
main 
Title for plot. 
by 
An object with 'start', 'end', and 'width' methods. Passed to 
FUN 
The function, found via 'match.fun', to be applied to each window of
'x'. Passed to 
start 
Start of the window. If 'by' is missing, then must supply two of the 'start', 'end', 'width'. If 'window' is provided then you don't have to specify it. 
end 
End of the window. If 'by' is missing, then must supply two of the 'start', 'end', 'width'. If 'window' is provided then you don't have to specify it. 
width 
Width of the window. If 'by' is missing, then must supply two of the 'start', 'end', 'width'. If 'window' is provided then you don't have to specify it. 
y 
A character indicate the varialbe column for which aggregation is
taken on. Notice for geom like 'boxplot', we don't compute or
aggregate the variable, we simply want to use the idenitcal y as y
axis, in that case please put y in the 
frequency 
Optional arguments that specify the sampling frequency within the window. 
delta 
Optional arguments that specify the sampling increment within the window. 
... 
Arguments passed to plot function. such as aes() and color. 
simplify 
A logical value specifying whether or not the result should be simplified to a vector or matrix if possible. 
window 
Integer value indicate window size. 
facets 
Faceting formula to use. 
type 

geom 
The geometric object to use display the data. 
A 'Layer'.
Tengfei Yin
library(GenomicRanges)
set.seed(1)
N < 1000
## ======================================================================
## 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))
## 36,37 doesn't work
## ggplot(gr) + stat_aggregate(y = "value",fill = "gray40")
## ggplot(gr) + stat_aggregate(window = 30, y = "value",fill = "gray40", geom = "histogram")
## ggplot(gr) + stat_aggregate(window = 100, fill = "gray40",y = "value",
## type = "max", geom = "histogram")