Skip to content

after_stat

after_stat(name: str) -> str

Map a variable the stat computes (ggplot2 after_stat()).

Another spelling of lets-plot's "..name..": aes(y=after_stat("density")) is aes(y="..density.."). Only a variable name is accepted, not an expression such as ggplot2's after_stat(count / max(count)). Text variables of the ggpubr / ggpmisc stats work too: after_stat("r.label") labels stat_cor with "R = 0.58" only (no p-value).

Parameters:

  • name (str) –

    A computed variable of the layer's stat, e.g. "count", "density", "level" (".width" for ggdist intervals), or a label such as "r.label", "p.label", "rr.label" (stat_cor) and "eq.label", "rr.label", "adj.rr.label", "p.value.label", "n.label" (stat_poly_eq).

Returns:

  • str –

    "..name..", for use in aes().

Raises:

Examples:

>>> from ggrust import *
>>> data = {"height": [150, 152, 158, 160, 161, 165, 170, 171, 178, 185]}
>>> plot = ggplot(data, aes("height", after_stat("density"))) + geom_histogram(bins=5)

A correlation label without the p-value:

>>> data = {"height": [150, 160, 165, 170, 175, 182, 190],
...         "weight": [52, 58, 63, 66, 74, 80, 88]}
>>> plot = (ggplot(data, aes("height", "weight")) + geom_point()
...         + stat_cor(aes(label=after_stat("r.label"))))

A correlation label without the p-value