lets_plot.stat_corr

lets_plot.stat_corr(mapping=None, *, data=None, geom=None, position=None, show_legend=None, sampling=None, tooltips=None, type='full', diag=None, flip=True, threshold=None, **other_args)

Computes correlations between numeric variables in the data and draws a correlation matrix. By default uses the tile geometry.

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

  • data (dict or DataFrame or GeoDataFrame) – 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.

  • geom (str) – The name of geometry used to draw correlation matrix. For example: ‘tile’ or ‘point’ or ‘text’.

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

  • show_legend (bool, default=True) – False - do not show legend for this layer.

  • sampling (FeatureSpec) – Result of the call to the sampling_xxx() function. Value None (or ‘none’) will disable sampling for this layer.

  • tooltips (layer_tooltips) – Result of the call to the layer_tooltips() function. Specifies appearance, style and content.

  • type ({‘upper’, ‘lower’, ‘full’}, default=’full’) – Type of matrix.

  • diag (bool) – Determines whether to fill the main diagonal with values. Default - True if ‘full’ matrix, else - False.

  • flip (bool, default=True) – If True the y axis is flipped.

  • threshold (float, default=0.0) – Minimal correlation abs value to be included in result.

Returns

Geom object specification.

Return type

LayerSpec

Note

The correlation statistic computes the following variables that can be used in the aesthetic mapping:

  • ..x.. : X coordinates.

  • ..y.. : Y coordinates.

  • ..corr.. : correlation (in range -1..1).

  • ..corr_abs.. : absolute value of correlation (in range 0..1).

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4np.random.seed(42)
5data = {var: np.random.poisson(size=10) for var in 'abcdef'}
6ggplot(data) + stat_corr() + coord_fixed()