stat_summarise | R Documentation |
Applies a function to a specified grouping variable
stat_summarise(
mapping = NULL,
data = NULL,
geom = "bar",
position = "identity",
...,
fun = NULL,
args = list(),
show.legend = NA,
inherit.aes = TRUE
)
stat_summarize(
mapping = NULL,
data = NULL,
geom = "bar",
position = "identity",
...,
fun = NULL,
args = list(),
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 |
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. |
... |
additional arguments to pass to layer. |
fun |
Summarising function to use. If no function provided it will default to length. |
args |
List of additional arguments passed to the function. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
An object of class StatSummarise
(inherits from Stat
, ggproto
, gg
) of length 5.
An object of class StatSummarize
(inherits from Stat
, ggproto
, gg
) of length 5.
A Layer object to be added to a ggplot
Using stat_summarise requires that you use domain
as an aesthetic
mapping. This allows you to summarise other data instead of assuming
that x
is the function's domain
.
library(tidyr)
i <- gather(iris,"key","value",-Species)
ggplot(i, aes(Species, fill = key, domain = value)) +
geom_bar(aes(y = after_stat(summarise)), stat = "summarise", fun = mean) +
stat_summarise(aes(y = after_stat(summarise),
label = after_stat(summarise)),
position = position_stack(vjust = .5), geom = "text", fun = mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.