Skip to content

sampling_fraction

sampling_fraction(
    fraction: float, seed: int | None = None
) -> FeatureSpec

Keep a random share of the rows (ggrust extension, not in lets_plot).

fraction=0.2 keeps 20 percent of the rows (rounded, at least one), chosen as sampling_random chooses them.

Parameters:

  • fraction (float) –

    Share of the rows to keep, greater than 0 and at most 1.

  • seed (int, default: None ) –

    Seed of the random generator.

Returns:

  • FeatureSpec –

    The sampling, for a layer's sampling=.

Raises:

Examples:

>>> import numpy as np
>>> from ggrust import *
>>> rng = np.random.default_rng(1)
>>> data = {"x": rng.normal(size=10_000), "y": rng.normal(size=10_000)}
>>> plot = ggplot(data, aes("x", "y")) + geom_point(sampling=sampling_fraction(0.1))