density

densityNode

A sample drawn as the curve of its density: a kernel density estimate worked out from the readings themselves, so the curve is one line of chalk rather than a column of heights computed elsewhere. Which coordinate carries the readings is the axis they are measured on, and the estimate rises up the other — x: spreads them along x with the curve standing over it, y: turns the picture a quarter turn. Two coordinates are two samples with no axis left for the estimate to rise up, and are refused. Drawn only across the range the readings cover, and trimmed square at each end for the reason a violin is: a density claimed past the largest reading is a picture of measurements nobody took. The area under it is 1. bandwidth: is parametised, which is most of what this mark is for — the same readings under a bandwidth the reader is dragging, bumps appearing and flattening as they go.

Only withxyplane

#Attributes

xImplicitAnimatable
The readings — numbers written out, or a dataset column bound whole. The sample itself, not a curve worked out by hand; writing them on x spreads the density along x, with the estimate rising up y.Can be written as shorthand: density:value
yAnimatable
The readings when the sample is measured up the y axis — the same picture, turned a quarter turn, with the estimate running out along x. Not with x:.
bandwidthAnimatable
The width of the kernel each reading is smoothed over, in the readings' own units. Left out, Silverman's rule of thumb, 0.9 × min(σ, IQR ÷ 1.34) × n^(−1/5). Smaller shows every bump in the sample and larger smooths them away; parametised, so a slider drives it. A written number must be positive.
colourAnimatable
neutralredorangeyellowgreentealbluepurplepinkgreywhiteblack
Also written: colorColour.
Defaultpurple
widthAnimatable
Stroke width, as a curve's is.
Default2
fillAnimatable
Wash the area under the curve in its own colour. Off by default: a family of densities at three bandwidths reads as three lines, and three washes over one another read as nothing.
Defaultfalse
opacityAnimatable
Opacity.
Default1
Text drawn beside the element — rich text, so $maths$ and inline formatting render. Placed at the curve's peak, which is where a family of densities is told apart.
hiddenAnimatable
Declared but not drawn. Animatable — hidden: true !cue.to{false}(at: 2) reveals it — and unlike a cue, a hidden element still frames the plot, so nothing moves when it appears.
Defaultfalse
Also written: lockedKeeps the reader from editing this element on an editable: graph. Nothing at all on a graph that is not editable.
Defaultfalse
text-sizeAnimatable
Text size.
Default20
layerAnimatable
Paint order among the marks: a higher layer is drawn later, on top; equal or omitted, the marks stack in document order (later on top).

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

modeDerived
The reading the curve peaks at — the sample's mode as the estimate sees it, which moves with the bandwidth.
peakDerived
The density at that reading — how tall the curve is at its highest.
current-bandwidthDerived
The width actually smoothed by: the one written, or the one Silverman's rule chose — which is the number nobody knows without being told it. Named apart from the bandwidth attribute, which says what was asked for rather than what was used.

#Allowed in

#Examples

density(x: #sample.height)
density(x: #sample.height; bandwidth: h; colour: purple)
parameter(var: h; from: 0.2; to: 4; value: 1; label: bandwidth)
density(x: #avp.income; bandwidth: 0.5; label: narrow)
density(x: #avp.income; bandwidth: 2; label: wide; colour: teal)