lets_plot.ggmarginal#
- lets_plot.ggmarginal(sides: str, *, size=None, layer: LayerSpec | FeatureSpecArray) FeatureSpec #
Convert a given geometry layer to a marginal layer. You can add one or more marginal layers to a plot to create a marginal plot.
- Parameters:
- sidesstr
A string specifying which sides of the plot the marginal layer will appear on. It should be set to a string containing any of “trbl”, for top, right, bottom, and left.
- sizenumber or list of numbers, default=0.1
Size of marginal geometry (width or height, depending on the margin side) as a fraction of the entire plotting area of the plot. The value should be in range [0.01..0.95].
- layerLayerSpec
A marginal geometry layer. The result of calling of the geom_xxx() / stat_xxx() function. Marginal plot works best with density,`histogram`,`boxplot`,`violin` and freqpoly geometry layers.
- Returns:
- FeatureSpec
An object specifying a marginal geometry layer or a list of marginal geometry layers.
Notes
A marginal plot is a scatterplot (sometimes a 2D density plot or other bivariate plot) that has histograms, boxplots, or other distribution visualization layers in the margins of the x- and y-axes.
Examples
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4LetsPlot.set_theme(theme_light()) 5 6np.random.seed(0) 7 8cov0=[[1, -.8], 9 [-.8, 1]] 10cov1=[[ 10, .1], 11 [.1, .1]] 12 13x0, y0 = np.random.multivariate_normal(mean=[-2,0], cov=cov0, size=200).T 14x1, y1 = np.random.multivariate_normal(mean=[0,1], cov=cov1, size=200).T 15 16data = dict( 17 x = np.concatenate((x0,x1)), 18 y = np.concatenate((y0,y1)), 19 c = ["A"]*200 + ["B"]*200 20) 21 22p = ggplot(data, aes("x", "y", color="c", fill="c")) + geom_point() 23p + ggmarginal("tr", layer=geom_density(alpha=0.3, show_legend=False))