Skip to content

geom_quasirandom

geom_quasirandom(
    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,
    orientation: Literal["x", "y"] | None = None,
    method: Literal | None = None,
    width: Number | None = None,
    varwidth: bool | None = None,
    bandwidth: Number | None = None,
    nbins: int | None = None,
    dodge_width: Number | None = None,
    seed: int | None = None,
    color_by: str | None = None,
    fill_by: str | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> LayerSpec

Quasirandom plot: points spread sideways within the density of their x.

As geom_quasirandom in the R package ggbeeswarm: like a violin made of points. Each point moves by up to width times the density at its y (scaled to a maximum of 1), along a van der Corput sequence by rank, so the layout is deterministic and evenly spread.

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes(). Needs x and y.

  • data (DataFrame or dict, default: None ) –

    Layer data; inherits the plot data when None.

  • stat (str, default: None ) –

    Statistical transformation, by name; "quasirandom" by default.

  • position (str or FeatureSpec, default: None ) –

    Position adjustment. "dodge" or position_dodge(width) sets dodge_width (0.95 without a width); others apply after the spread.

  • 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 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".

  • orientation ((x, y), default: "x" ) –

    "y" spreads along the y axis; a discrete y with a continuous x picks it by default.

  • method ((quasirandom, pseudorandom, smiley, maxout, frowney, minout), default: "quasirandom" ) –

    "quasirandom": van der Corput offsets; "pseudorandom": seeded uniform offsets; "smiley" (alias "maxout") and "frowney" ("minout"): within each density bin, alternate points to the outside, low values outermost (smiley) or high values outermost (frowney).

  • width (float, default: None ) –

    Largest offset, in x units; 0.4 times the x resolution by default.

  • varwidth (bool, default: False ) –

    True narrows each x's spread by the square root of its share of the largest group's count.

  • bandwidth (float, default: 0.5 ) –

    Multiplier of R's default (nrd0) density bandwidth.

  • nbins (int, default: None ) –

    Number of density points (1024 for quasirandom and pseudorandom; for smiley and frowney, the bins, one per 5 points by default).

  • dodge_width (float, default: None ) –

    Dodge groups at one x side by side, position_dodge(width) style, and spread each group on its own. Without it, every group at an x shares one spread.

  • seed (int, default: None ) –

    Random seed of method="pseudorandom".

  • color_by (str, default: None ) –

    Aesthetic the color scale applies to ("color" or "fill").

  • fill_by (str, default: None ) –

    Aesthetic the fill scale applies to ("fill" or "color").

  • na_rm (bool, default: None ) –

    True removes rows with missing values silently.

  • **other_args (Any) –

    Constant aesthetics (color, size, shape, ...).

Returns:

  • LayerSpec –

    The layer.

Raises:

Examples:

>>> from ggrust import *
>>> data = {"day": ["Mon"] * 8 + ["Tue"] * 8,
...         "minutes": [31, 35, 35, 36, 38, 40, 41, 47, 25, 28, 30, 30, 30, 33, 37, 45]}
>>> plot = ggplot(data, aes("day", "minutes")) + geom_violin() + geom_quasirandom()