lets_plot.geom_boxplot

lets_plot.geom_boxplot(mapping=None, *, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, fatten=None, outlier_color=None, outlier_fill=None, outlier_shape=None, outlier_size=None, varwidth=None, **other_args)

Display the distribution of data based on a five number summary (“minimum”, first quartile (Q1), median, third quartile (Q3), and “maximum”), and “outlying” points individually.

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

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=’boxplot’

The statistical transformation to use on the data for this layer, as a string.

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. Value None (or ‘none’) will disable sampling for this layer.

tooltipslayer_tooltips

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

fattenfloat, default=1.0

A multiplicative factor applied to size of the middle bar.

outlier_colorstr

Default color aesthetic for outliers.

outlier_fillstr

Default fill aesthetic for outliers.

outlier_shapeint

Default shape aesthetic for outliers.

outlier_sizefloat

Default size aesthetic for outliers.

varwidthbool, default=False

If False make a standard box plot. If True, boxes are drawn with widths proportional to the square-roots of the number of observations in the groups.

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:

  • ..lower.. : lower hinge, 25% quantile.

  • ..middle.. : median, 50% quantile.

  • ..upper.. : upper hinge, 75% quantile.

  • ..ymin.. : lower whisker = smallest observation greater than or equal to lower hinge - 1.5 * IQR.

  • ..ymax.. : upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR.

geom_boxplot() understands the following aesthetics mappings:

  • lower : lower hinge.

  • middle : median.

  • upper : upper hinge.

  • ymin : lower whisker.

  • ymax : upper whisker.

  • alpha : transparency level of a layer. Understands numbers between 0 and 1.

  • color (colour) : color of a 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’.

  • width : width of boxplot [0..1].

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4n = 100
5np.random.seed(42)
6x = np.random.choice(['a', 'b', 'c'], size=n)
7y = np.random.normal(size=n)
8ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + \
9    geom_boxplot()