geom_quantile ¶
geom_quantile(
mapping: FeatureSpec | None = None,
*,
data: PlotData | None = None,
stat: str | None = None,
position: Position | None = None,
show_legend: bool | None = None,
inherit_aes: bool | None = None,
manual_key: ManualKey | None = None,
sampling: Sampling | None = None,
tooltips: Tooltips | None = None,
quantiles: float | Sequence[float] | None = None,
formula: str | None = None,
method: str | None = None,
na_rm: bool | None = None,
**other_args: Any,
) -> LayerSpec
Draw quantile regression lines (stat="quantile", ggplot2).
One straight line per group and quantile: for quantile tau, the line below
which about a share tau of the points lie (quantreg::rq(y ~ x)). The stat
computes ..quantile.., so aes(color="..quantile..") tells the lines
apart.
Parameters:
-
mapping(FeatureSpec, default:None) –Aesthetic mapping from
aes():x,y(required),color,alpha,size,linetype,group. -
data(DataFrame or dict, default:None) –Layer data; inherits the plot data when None.
-
stat(str, default:None) –Statistical transformation, by name;
"quantile"when None. -
position(str or FeatureSpec, default:None) –Position adjustment: a name such as
"identity"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.
-
manual_key(str or FeatureSpec, default:None) –This layer's key in a manual legend: a label, or
layer_key(). -
sampling((str, int or FeatureSpec), default:None) –Rows to draw: a
sampling_*()spec, an intnor"none". -
tooltips(FeatureSpec or list of str, default:None) –Tooltip content:
layer_tooltips(), a list of column names, or"none". -
quantiles(float or list of float, default:[0.25, 0.5, 0.75]) –Probabilities strictly between 0 and 1, one line each.
-
formula(str, default:"y ~ x") –Only the linear
"y ~ x"is supported. -
method(str, default:"rq") –Only
"rq"is supported. -
na_rm(bool, default:None) –True removes rows with missing values silently; otherwise with a warning.
-
**other_args(Any) –Constant aesthetics such as
color="black"orsize=1.
Returns:
-
LayerSpec–The layer.
Raises:
-
SpecError–If
formulaormethodasks for another model.
Examples:
>>> from ggrust import *
>>> import numpy as np
>>> rng = np.random.default_rng(1)
>>> engine = rng.uniform(1, 6, 200)
>>> data = {"engine": engine, "mpg": 40 - 4 * engine + rng.normal(0, 1, 200) * engine}
>>> plot = ggplot(data, aes("engine", "mpg")) + geom_point() + geom_quantile()
The median and the 5% and 95% quantile lines, one set per group:
>>> from ggrust.data import mpg
>>> plot = (ggplot(mpg, aes("displ", "hwy", color="drv")) + geom_point(alpha=0.4)
... + geom_quantile(quantiles=[0.05, 0.5, 0.95]))
The median and the 5% and 95% quantile lines, one set per group