geom_bin_2d | R Documentation |
Divides the plane into rectangles, counts the number of cases in
each rectangle, and then (by default) maps the number of cases to the
rectangle's fill. This is a useful alternative to geom_point()
in the presence of overplotting.
geom_bin_2d(
mapping = NULL,
data = NULL,
stat = "bin2d",
position = "identity",
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_bin_2d(
mapping = NULL,
data = NULL,
geom = "tile",
position = "identity",
...,
bins = 30,
binwidth = NULL,
center = NULL,
boundary = NULL,
breaks = NULL,
drop = TRUE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom , stat |
Use to override the default connection between
|
bins |
Number of bins. Overridden by |
binwidth |
The width of the bins. Can be specified as a numeric value
or as a function that takes x after scale transformation as input and
returns a single numeric value. When specifying a function along with a
grouping structure, the function will be called once per group.
The default is to use the number of bins in The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds. |
center , boundary |
bin position specifiers. Only one, |
breaks |
Alternatively, you can supply a numeric vector giving
the bin boundaries. Overrides |
drop |
if |
stat_bin_2d()
understands the following aesthetics (required aesthetics are in bold):
x
y
fill
group
weight
Learn more about setting these aesthetics in vignette("ggplot2-specs")
.
These are calculated by the 'stat' part of layers and can be accessed with delayed evaluation.
after_stat(count)
number of points in bin.
after_stat(density)
density of points in bin, scaled to integrate to 1.
after_stat(ncount)
count, scaled to maximum of 1.
after_stat(ndensity)
density, scaled to a maximum of 1.
The arguments bins
, binwidth
, breaks
, center
, and boundary
can
be set separately for the x and y directions. When given as a scalar, one
value applies to both directions. When given as a vector of length two,
the first is applied to the x direction and the second to the y direction.
Alternatively, these can be a named list containing x
and y
elements,
for example list(x = 10, y = 20)
.
stat_bin_hex()
for hexagonal binning
d <- ggplot(diamonds, aes(x, y)) + xlim(4, 10) + ylim(4, 10)
d + geom_bin_2d()
# You can control the size of the bins by specifying the number of
# bins in each direction:
d + geom_bin_2d(bins = 10)
d + geom_bin_2d(bins = list(x = 30, y = 10))
# Or by specifying the width of the bins
d + geom_bin_2d(binwidth = c(0.1, 0.1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.