| Title: | Multiple Summary Statistics for Binned Stats/Geometries | 
| Version: | 1.0.1 | 
| Description: | Provides the ggplot binning layer stat_summaries_hex(), which functions similar to its singular form, but allows the use of multiple statistics per bin. Those statistics can be mapped to multiple bin aesthetics. | 
| URL: | https://github.com/flying-sheep/ggplot.multistats | 
| BugReports: | https://github.com/flying-sheep/ggplot.multistats/issues | 
| License: | GPL-3 | 
| Encoding: | UTF-8 | 
| Imports: | methods, rlang, scales, hexbin, ggplot2 (≥ 3.3.0) | 
| RoxygenNote: | 7.2.3 | 
| NeedsCompilation: | no | 
| Packaged: | 2024-09-25 12:16:05 UTC; phil | 
| Author: | Philipp Angerer | 
| Maintainer: | Philipp Angerer <phil.angerer@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2024-09-25 12:40:10 UTC | 
Draw a Hexagon
Description
The default legend key drawing function for stat_summaries_hex.
This function can be used as key_glyph parameter by any layer.
Usage
draw_key_hexagon(data, params, size)
Arguments
| data | A single row data frame containing the scaled aesthetics to display in this key | 
| params | A list of additional parameters supplied to the geom. | 
| size | Width and height of key in mm. | 
Value
A hexagonal polygonGrob.
See Also
The legend key drawing functions built into ggplot:
draw_key.
Examples
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_hex(key_glyph = 'hexagon') +
  guides(fill = 'legend')
Normalize a List of Functions
Description
Takes a list of functions and function names (or a vector of function names) and names it. Requires all entries with functions to be named and adds names to functions that were specified as names.
Usage
normalize_function_list(funs)
Arguments
| funs | Valid list or vector of function names and/or functions. | 
Value
Named list or character vector of functions.
Examples
normalize_function_list(c(value = 'mean'))
normalize_function_list(c('median', n = 'length'))
normalize_function_list(list('median', n = length))
normalize_function_list(list(Sum = sum, Custom = function(x) sum(nchar(as.character(x)))))
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  | 
| data | The data to be displayed in this layer. There are three options: If  A  A  | 
| geom | The geometric object to use to display the data, either as a
 | 
| position | Position adjustment, either as a string naming the adjustment
(e.g.  | 
| ... | Other arguments passed on to  | 
| 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  | 
| drop | drop if the output of  | 
| funs | A list or vector of functions and function names.
See  | 
| na.rm | If  | 
| show.legend | logical. Should this layer be included in the legends?
 | 
| inherit.aes | If  | 
| key_glyph | A legend key drawing function or a string providing
the function name minus the  | 
Format
An object of class StatSummariesHex (inherits from Stat, ggproto, gg) of length 4.
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 `after_stat(value)` containing the mean
ggplot_base + stat_summaries_hex(aes(fill = after_stat(value)), bins = 5)
# but you can specify your own stats
ggplot_base + stat_summaries_hex(
  aes(fill = after_stat(median), alpha = after_stat(n)),
  funs = c('median', n = 'length'),
  bins = 5)