Last data update: 2014.03.03

R: Binning method
stat_binR Documentation

Binning method

Description

Binning method especially for Rle and RleList, for data.frame it's just calling ggplot2::stat_bin.

Usage

## S4 method for signature 'ANY'
stat_bin(data, ...)

## S4 method for signature 'Rle'
stat_bin(data, ..., binwidth, nbin = 30,
         xlab, ylab, main, geom = c("bar", "heatmap"),
         type = c("viewSums","viewMins",
                                  "viewMaxs", "viewMeans"))
## S4 method for signature 'RleList'
stat_bin(data, ..., binwidth, nbin = 30,
          xlab, ylab, main,
          indName = "sample",
          geom = c("bar", "heatmap"),
          type = c("viewSums","viewMins",
          "viewMaxs", "viewMeans"))

Arguments

data

Typically a data.frame or Rle or RleList object.

...

arguments passed to aesthetics mapping.

binwidth

width of the bins.

nbin

number of bins.

xlab

x label.

ylab

y label.

main

title.

indName

when faceted by a RleList, name used for labeling faceted factor. Default is 'sample'.

geom

geometric types.

type

statistical summary method used within bins, shown as bar height or heatmap colors.

Value

a ggplot object.

Author(s)

Tengfei Yin

Examples

library(IRanges)
lambda <- c(rep(0.001, 4500), seq(0.001, 10, length = 500), 
            seq(10, 0.001, length = 500))
xVector <- rpois(1e4, lambda)
xRle <- Rle(xVector)
xRleList <- RleList(xRle, 2L * xRle)

ggplot() + stat_bin(xRle)
ggplot(xRle) + stat_bin()
ggplot(xRle) + stat_bin(nbin = 100)
ggplot(xRle) + stat_bin(binwidth = 200)

p1 <- ggplot(xRle) + stat_bin(type = "viewMeans")
p2 <- ggplot(xRle) + stat_bin(type = "viewSums")
## y scale are different.
tracks(viewMeans = p1, viewSums = p2)

ggplot(xRle) + stat_bin(geom = "heatmap")
ggplot(xRle) + stat_bin(nbin = 100, geom = "heatmap")
ggplot(xRle) + stat_bin(binwidth = 200, geom = "heatmap")

## for RleList
ggplot(xRleList) + stat_bin()
ggplot(xRleList) + stat_bin(nbin = 100)
ggplot(xRleList) + stat_bin(binwidth = 200)

p1 <- ggplot(xRleList) + stat_bin(type = "viewMeans")
p2 <- ggplot(xRleList) + stat_bin(type = "viewSums")
## y scale are different.
tracks(viewMeans = p1, viewSums = p2)

ggplot(xRleList) + stat_bin(geom = "heatmap")
ggplot(xRleList) + stat_bin(nbin = 100, geom = "heatmap")
ggplot(xRleList) + stat_bin(binwidth = 200, geom = "heatmap")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ggbio)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: ggplot2
Need specific help about ggbio? try mailing 
 the maintainer or visit http://tengfei.github.com/ggbio/

Attaching package: 'ggbio'

The following objects are masked from 'package:ggplot2':

    geom_bar, geom_rect, geom_segment, ggsave, stat_bin, stat_identity,
    xlim

Warning message:
replacing previous import 'ggplot2::Position' by 'BiocGenerics::Position' when loading 'ggbio' 
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/ggbio/stat_bin-method.Rd_%03d_medium.png", width=480, height=480)
> ### Name: stat_bin
> ### Title: Binning method
> ### Aliases: stat_bin stat_bin,missing-method stat_bin,uneval-method
> ###   stat_bin,ANY-method stat_bin,Rle-method stat_bin,RleList-method
> 
> ### ** Examples
> 
> library(IRanges)
Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

> lambda <- c(rep(0.001, 4500), seq(0.001, 10, length = 500), 
+             seq(10, 0.001, length = 500))
> xVector <- rpois(1e4, lambda)
> xRle <- Rle(xVector)
> xRleList <- RleList(xRle, 2L * xRle)
> 
> ggplot() + stat_bin(xRle)
Default use binwidth: range/30
> ggplot(xRle) + stat_bin()
Default use binwidth: range/30
> ggplot(xRle) + stat_bin(nbin = 100)
Default use binwidth: range/100
> ggplot(xRle) + stat_bin(binwidth = 200)
> 
> p1 <- ggplot(xRle) + stat_bin(type = "viewMeans")
Default use binwidth: range/30
> p2 <- ggplot(xRle) + stat_bin(type = "viewSums")
Default use binwidth: range/30
> ## y scale are different.
> tracks(viewMeans = p1, viewSums = p2)
> 
> ggplot(xRle) + stat_bin(geom = "heatmap")
Default use binwidth: range/30
> ggplot(xRle) + stat_bin(nbin = 100, geom = "heatmap")
Default use binwidth: range/100
> ggplot(xRle) + stat_bin(binwidth = 200, geom = "heatmap")
> 
> ## for RleList
> ggplot(xRleList) + stat_bin()
Default use binwidth: range/30
> ggplot(xRleList) + stat_bin(nbin = 100)
Default use binwidth: range/100
> ggplot(xRleList) + stat_bin(binwidth = 200)
> 
> p1 <- ggplot(xRleList) + stat_bin(type = "viewMeans")
Default use binwidth: range/30
> p2 <- ggplot(xRleList) + stat_bin(type = "viewSums")
Default use binwidth: range/30
> ## y scale are different.
> tracks(viewMeans = p1, viewSums = p2)
> 
> ggplot(xRleList) + stat_bin(geom = "heatmap")
Default use binwidth: range/30
> ggplot(xRleList) + stat_bin(nbin = 100, geom = "heatmap")
Default use binwidth: range/100
> ggplot(xRleList) + stat_bin(binwidth = 200, geom = "heatmap")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>