stat_summaries_hex {ggplot.multistats}R Documentation

Multi-Stat Binning Layer

Description

Very similar to stat_summary_hex, but allows for multiple stats to be captured using the funs parameter.

Usage

stat_summaries_hex(mapping = NULL, data = NULL, geom = "hex",
  position = "identity", ..., bins = 30, binwidth = NULL,
  drop = TRUE, funs = c(value = "mean"), na.rm = FALSE,
  show.legend = NA, inherit.aes = TRUE, key_glyph = NULL)

StatSummariesHex

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

geom

The geometric object to use display the data

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

bins

numeric vector giving number of bins in both vertical and horizontal directions. Set to 30 by default.

binwidth

Numeric vector giving bin width in both vertical and horizontal directions. Overrides bins if both set.

drop

drop if the output of fun is NA.

funs

A list or vector of functions and function names. See normalize_function_list for details.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

key_glyph

A legend key drawing function or a string providing the function name minus the draw_key_ prefix. The default is draw_key_hexagon.

Format

An object of class StatSummariesHex (inherits from Stat, ggproto, gg) of length 3.

See Also

normalize_function_list for the funs parameter and draw_key_hexagon for the legend entry.

Examples

library(ggplot2)
# Define the variable used for the stats using z
ggplot_base <- ggplot(iris, aes(Sepal.Width, Sepal.Length, z = Petal.Width))
# The default is creating `stat(value)` containing the mean
ggplot_base + stat_summaries_hex(aes(fill = stat(value)), bins = 5)
# but you can specify your own stats
ggplot_base + stat_summaries_hex(
  aes(fill = stat(median), alpha = stat(n)),
  funs = c('median', n = 'length'),
  bins = 5)


[Package ggplot.multistats version 1.0.0 Index]