lets_plot.layer

lets_plot.layer(geom=None, stat=None, data=None, mapping=None, position=None, **kwargs)

Create a new layer.

Parameters
geomstr

The geometric object to use to display the data.

statstr, default=’identity’

The statistical transformation to use on the data for this layer, as a string. Supported transformations: ‘identity’ (leaves the data unchanged), ‘count’ (count number of points with same x-axis coordinate), ‘bin’ (count number of points with x-axis coordinate in the same bin), ‘smooth’ (perform smoothing - linear default), ‘density’ (compute and draw kernel density estimate).

datadict or Pandas 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.

mappingFeatureSpec

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

positionstr or FeatureSpec

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

kwargs:

Other arguments passed on to 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

A layer is a combination of data, stat and geom with a potential position adjustment. Usually layers are created using geom_* or stat_* calls but they can be created directly using this function.

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4n = 50
5np.random.seed(42)
6x = np.random.uniform(-1, 1, size=n)
7y = 25 * x ** 2 + np.random.normal(size=n)
8ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + layer(geom='point')