# Analyses

## Histogram

AlgebraOfGraphics.histogramFunction
histogram(; bins=automatic, weights=automatic, normalization=:none)

Compute a histogram. bins can be an Int to create that number of equal-width bins over the range of values. Alternatively, it can be a sorted iterable of bin edges. The histogram can be normalized by setting normalization. Possible values are:

• :pdf: Normalize by sum of weights and bin sizes. Resulting histogram has norm 1 and represents a PDF.
• :density: Normalize by bin sizes only. Resulting histogram represents count density of input and does not have norm 1.
• :probability: Normalize by sum of weights only. Resulting histogram represents the fraction of probability mass for each bin and does not have norm 1.
• :none: Do not normalize.

Weighted data is supported via the keyword weights.

Note

Normalizations are computed withing groups. For example, in the case of normalization=:pdf, sum of weights within each group will be equal to 1.

source
using AlgebraOfGraphics, CairoMakie
set_aog_theme!()

df = (x=randn(1000), y=randn(1000), z=rand(["a", "b", "c"], 1000))
specs = data(df) * mapping(:x, layout=:z) * histogram(bins=range(-2, 2, length=15))
draw(specs) specs = data(df) * mapping(:x, dodge=:z, color=:z) * histogram(bins=range(-2, 2, length=15))
draw(specs) specs = data(df) * mapping(:x, stack=:z, color=:z) * histogram(bins=range(-2, 2, length=15))
draw(specs) data(df) * mapping(:x, :y, layout=:z) * histogram(bins=15) |> draw ## Density

AlgebraOfGraphics.densityFunction
density(; datalimits, npoints, kernel, bandwidth)

Fit a kernel density estimation of data. Here, datalimits specifies the range for which the density should be calculated, npoints is the number of points used by Makie to draw the line and kernel and bandwidth are forwarded to KernelDensity.kde.

source
df = (x=randn(5000), y=randn(5000), z=rand(["a", "b", "c", "d"], 5000))
datalimits = ((-2.5, 2.5),)
xz = data(df) * mapping(:x, layout=:z) * AlgebraOfGraphics.density(; datalimits)
axis = (; ylabel="")
draw(xz; axis) data(df) * mapping(:x, :y, layout=:z) * AlgebraOfGraphics.density(npoints=50) |> draw