Skip to content

geom_beeswarm

geom_beeswarm(
    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,
    cex: Number | None = None,
    side: Literal[-1, 0, 1] | None = None,
    priority: Literal | 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

Beeswarm plot: points of each x moved sideways so that none overlap.

As geom_beeswarm in the R package ggbeeswarm. A point is 1/100 of each axis range across (times cex; a discrete axis counts its levels), so the layout depends on the data ranges, not on the plot size.

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; "beeswarm" 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 swarm.

  • 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" swarms along the y axis; a discrete y with a continuous x picks it by default.

  • method ((swarm, compactswarm, center, square, hex), default: "swarm" ) –

    "swarm" places each point (in priority order) at the free spot nearest the centre; "compactswarm" places the point that fits nearest the centre first, for tighter swarms. "center", "square" and "hex" bin y into rows one point high (moving points to the row middle) and lay each row out centred, on a square grid or on a hexagonal grid.

  • cex (float, default: 1 ) –

    Point spacing, as a multiple of the default.

  • side ((-1, 0, 1), default: -1 ) –

    1 swarms to the right only, -1 to the left only, 0 both ways.

  • priority ((ascending, descending, density, random, none), default: "ascending" ) –

    Order of placement for the swarm methods: by y, by density (densest first), random (seeded), or data order.

  • dodge_width (float, default: None ) –

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

  • seed (int, default: None ) –

    Random seed of priority="random".

  • 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:

  • SpecError –

    If method, priority, side, cex or dodge_width is not one of the accepted values.

  • UnsupportedValueError –

    If a numeric parameter is not a number.

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_beeswarm(cex=3)