stat_summary ¶
stat_summary(
mapping: FeatureSpec | None = None,
*,
data: PlotData | None = None,
geom: str | None = None,
position: Position | None = None,
show_legend: bool | None = None,
inherit_aes: bool | None = None,
sampling: Sampling | None = None,
tooltips: Tooltips | None = None,
orientation: str | None = None,
fun: Literal | None = None,
fun_min: Literal | None = None,
fun_max: Literal | None = None,
fun_data: Literal | None = None,
fun_args: Mapping[str, Number] | None = None,
quantiles: Sequence[float] | None = None,
color_by: str | None = None,
fill_by: str | None = None,
na_rm: bool | None = None,
**other_args: Any,
) -> LayerSpec
Summarise y at every distinct x (stat="summary"), drawn as point ranges.
The stat computes y (fun, default mean), ymin (fun_min, default
min) and ymax (fun_max, default max) per group and x.
Parameters:
-
mapping(FeatureSpec, default:None) –Aesthetic mapping from
aes(). -
data(DataFrame or dict, default:None) –Layer data; inherits the plot data when None.
-
geom(str, default:"pointrange") –Geom that draws the summary, e.g.
"crossbar","errorbar","point". -
position(str or FeatureSpec, default:None) –Position adjustment: a name such as
"dodge"or aposition_*()spec. -
show_legend(bool, default:None) –False hides this layer from the legend.
-
inherit_aes(bool, default:None) –False ignores the plot's default mapping for this layer.
-
sampling(str or FeatureSpec, default:None) –lets_plot sampling; accepted and ignored, as ggrust draws every row.
-
tooltips(FeatureSpec or list of str, default:None) –Tooltip content:
layer_tooltips(), a list of column names, or"none"to disable tooltips (HTML output). -
orientation(str, default:None) –"y"summarises x per y (a discrete y and a continuous x pick it by default). -
fun((count, sum, mean, median, min, max, lq, mq, uq), default:"count") –Aggregate for
y.lq,mqanduqare the threequantiles. -
fun_min(str, default:"min") –Aggregate for
ymin; the same names asfun. -
fun_max(str, default:"max") –Aggregate for
ymax; the same names asfun. -
fun_data((mean_se, mean_sdl), default:"mean_se") –ggplot2 shortcut that sets all three: the mean, plus and minus
multstandard errors ("mean_se",mult1) or standard deviations ("mean_sdl",mult2). Cannot be combined withfun,fun_minorfun_max. Not in lets_plot. -
fun_args(dict, default:None) –Arguments of
fun_data:{"mult": k}. -
quantiles(list of float, default:[0.25, 0.5, 0.75]) –The probabilities of
lq,mqanduq; three numbers in 0..1. -
color_by(str, default:None) –Aesthetic the
colorscale applies to ("color"or"fill"). -
fill_by(str, default:None) –Aesthetic the
fillscale applies to ("color"or"fill"). -
na_rm(bool, default:None) –True removes rows with missing values silently; otherwise they are removed with a warning.
-
**other_args(Any) –Constant aesthetics such as
color="red", and the geom's options.
Returns:
-
LayerSpec–The layer.
Examples:
>>> from ggrust import *
>>> data = {"day": ["mon", "mon", "tue", "tue", "tue"], "sales": [3, 5, 2, 6, 7]}
>>> plot = ggplot(data, aes("day", "sales")) + stat_summary(fun_data="mean_se")