lets_plot.geom_area_ridges

lets_plot.geom_area_ridges(mapping=None, *, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, trim=None, tails_cutoff=None, kernel=None, adjust=None, bw=None, n=None, fs_max=None, min_height=None, scale=None, quantiles=None, quantile_lines=None, **other_args)

Plot the sum of the y and height aesthetics versus x. Heights of the ridges are relatively scaled.

Parameters
mappingFeatureSpec

Set of aesthetic mappings created by aes() function. Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.

datadict or DataFrame or polars.DataFrame

The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.

statstr, default=’densityridges’

The statistical transformation to use on the data for this layer, as a string. Supported transformations: ‘identity’ (leaves the data unchanged), ‘densityridges’ (computes and draws kernel density estimate for each ridge).

positionstr or FeatureSpec

Position adjustment, either as a string (‘identity’, ‘stack’, ‘dodge’, …), or the result of a call to a position adjustment function.

show_legendbool, default=True

False - do not show legend for this layer.

samplingFeatureSpec

Result of the call to the sampling_xxx() function. To prevent any sampling for this layer pass value “none” (string “none”).

tooltipslayer_tooltips

Result of the call to the layer_tooltips() function. Specify appearance, style and content.

trimbool, default=False

Trim the tails of the ridges to the range of the data.

tails_cutofffloat

Extend domain of each ridge on tails_cutoff * bw if trim=False. tails_cutoff=None (default) extends domain to maximum (domain overall ridges).

kernelstr, default=’gaussian’

The kernel we use to calculate the density function. Choose among ‘gaussian’, ‘cosine’, ‘optcosine’, ‘rectangular’ (or ‘uniform’), ‘triangular’, ‘biweight’ (or ‘quartic’), ‘epanechikov’ (or ‘parabolic’).

bwstr or float

The method (or exact value) of bandwidth. Either a string (choose among ‘nrd0’ and ‘nrd’), or a float.

adjustfloat

Adjust the value of bandwidth by multiplying it. Change how smooth the frequency curve is.

nint, default=512

The number of sampled points for plotting the function.

fs_maxint, default=500

Maximum size of data to use density computation with ‘full scan’. For bigger data, less accurate but more efficient density computation is applied.

min_heightfloat, default=0.0

A height cutoff on the drawn ridges. All values that fall below this cutoff will be removed.

scalefloat, default=1.0

A multiplicative factor applied to height aesthetic. If scale = 1.0, the heights of a ridges are automatically scaled such that the ridge with height = 1.0 just touches the one above.

quantileslist of float, default=[0.25, 0.5, 0.75]

Draw horizontal lines at the given quantiles of the density estimate.

quantile_linesbool, default=False

Show the quantile lines.

other_args

Other arguments passed on to the layer. These are often aesthetics settings used to set an aesthetic to a fixed value, like color=’red’, fill=’blue’, size=3 or shape=21. They may also be parameters to the paired geom/stat.

Returns
LayerSpec

Geom object specification.

Notes

Computed variables:

  • ..height.. : density scaled for the ridges, according to area, counts or to a constant maximum height.

  • ..density.. : density estimate.

  • ..count.. : density * number of points.

  • ..scaled.. : density estimate, scaled to maximum of 1.

  • ..quantile.. : quantile estimate.

geom_area_ridges() understands the following aesthetics mappings:

  • x : x-axis coordinates.

  • y : y-axis coordinates.

  • height : height of the ridge. Assumed to be between 0 and 1, though this is not required.

  • alpha : transparency level of a layer. Accept values between 0 and 1.

  • color (colour) : color of the geometry lines. Can be continuous or discrete. For continuous value this will be a color gradient between two colors.

  • fill : color of geometry filling.

  • size : lines width.

  • linetype : type of the line of border. Codes and names: 0 = ‘blank’, 1 = ‘solid’, 2 = ‘dashed’, 3 = ‘dotted’, 4 = ‘dotdash’, 5 = ‘longdash’, 6 = ‘twodash’.

  • quantile : quantile values to draw quantile lines and fill quantiles of the geometry by color.

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4n, m = 10, 3
5np.random.seed(42)
6x = np.random.normal(size=n*m)
7y = np.repeat(np.arange(m), n)
8ggplot({'x': x, 'y': y}, aes('x', 'y')) + \
9    geom_area_ridges()

 1from lets_plot import *
 2LetsPlot.setup_html()
 3data = {
 4    "x": [1, 2, 3, 4, 5, 6],
 5    "y": ['a', 'a', 'a', 'a', 'a', 'a'],
 6    "h": [1, -2, 3, -4, 5, 4],
 7}
 8ggplot(data) + \
 9    geom_area_ridges(aes("x", "y", height="h"), \
10                     stat='identity', min_height=-2, \
11                     color="#756bb1", fill="#bcbddc")

 1import numpy as np
 2from lets_plot import *
 3LetsPlot.setup_html()
 4n, m = 50, 3
 5np.random.seed(42)
 6x = np.random.normal(size=n*m)
 7y = np.repeat(['a', 'b', 'c'], n)
 8ggplot({'x': x, 'y': y}, aes('x', 'y')) + \
 9    geom_area_ridges(aes(fill='..quantile..'), \
10                     quantiles=[.05, .25, .5, .75, .95], quantile_lines=True, \
11                     scale=1.5, kernel='triangular', color='black')