File: stat_bin.Rd

package info (click to toggle)
r-cran-ggplot2 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,412 kB
  • sloc: sh: 9; makefile: 1
file content (80 lines) | stat: -rw-r--r-- 2,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{stat_bin}
\alias{stat_bin}
\title{Bin data.}
\usage{
stat_bin(mapping = NULL, data = NULL, geom = "bar", position = "stack",
  width = 0.9, drop = FALSE, right = FALSE, binwidth = NULL,
  origin = NULL, breaks = NULL, ...)
}
\arguments{
\item{binwidth}{Bin width to use. Defaults to 1/30 of the range of the
data}

\item{breaks}{Actual breaks to use.  Overrides bin width and origin}

\item{origin}{Origin of first bin}

\item{width}{Width of bars when used with categorical data}

\item{right}{If \code{TRUE}, right-closed, left-open, if \code{FALSE},
the default, right-open, left-closed.}

\item{drop}{If TRUE, remove all bins with zero counts}

\item{mapping}{The aesthetic mapping, usually constructed with
\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
at the layer level if you are overriding the plot defaults.}

\item{data}{A layer specific dataset - only needed if you want to override
the plot defaults.}

\item{geom}{The geometric object to use display the data}

\item{position}{The position adjustment to use for overlappling points
on this layer}

\item{...}{other arguments passed on to \code{\link{layer}}. This can
include aesthetics whose values you want to set, not map. See
\code{\link{layer}} for more details.}
}
\value{
New data frame with additional columns:
  \item{count}{number of points in bin}
  \item{density}{density of points in bin, scaled to integrate to 1}
  \item{ncount}{count, scaled to maximum of 1}
  \item{ndensity}{density, scaled to maximum of 1}
}
\description{
Missing values are currently silently dropped.
}
\section{Aesthetics}{

\Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("stat", "bin")}
}
\examples{
\donttest{
simple <- data.frame(x = rep(1:10, each = 2))
base <- ggplot(simple, aes(x))
# By default, right = FALSE intervals are of the form [a, b)
base + stat_bin(binwidth = 1, drop = FALSE, right = FALSE, col = "black")
# If right = TRUE, and intervals are of the form (a, b]
base + stat_bin(binwidth = 1, drop = FALSE, right = TRUE, col = "black")

m <- ggplot(movies, aes(x=rating))
m + stat_bin()
m + stat_bin(binwidth=0.1)
m + stat_bin(breaks=seq(4,6, by=0.1))
# See geom_histogram for more histogram examples

# To create a unit area histogram, use aes(y = ..density..)
(linehist <- m + stat_bin(aes(y = ..density..), binwidth=0.1,
  geom="line", position="identity"))
linehist + stat_density(colour="blue", fill=NA)

# Also works with categorical variables
ggplot(movies, aes(x=mpaa)) + stat_bin()
qplot(mpaa, data=movies, stat="bin")
}
}