Geom.density

Draw a kernel density estimate from data. An alias for Geom.line with Stat.density.

Aesthetics

Arguments

Examples

plot(dataset("ggplot2", "diamonds"), x="Price", Geom.density)
Price -1×10⁴ 0 1×10⁴ 2×10⁴ 3×10⁴ 0.0000 0.0001 0.0002 0.0003 0.0004
plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut", Geom.density)
Price -1×10⁴ 0 1×10⁴ 2×10⁴ 3×10⁴ Ideal Premium Good Very Good Fair Cut 0.0000 0.0001 0.0002 0.0003 0.0004 0.0005
# adjusting bandwidth manually
dist = MixtureModel(Normal, [(0.5, 0.2), (1, 0.1)])
xs = rand(dist, 10^5)
plot(layer(x=xs, Geom.density, Theme(default_color=colorant"orange")),
layer(x=xs, Geom.density(bandwidth=0.0003), Theme(default_color=colorant"green")),
layer(x=xs, Geom.density(bandwidth=0.25), Theme(default_color=colorant"purple")),
Guide.manual_color_key("bandwidth", ["auto", "bw=0.0003", "bw=0.25"], ["orange", "green", "purple"]))
x -2 -1 0 1 2 3 auto bw=0.0003 bw=0.25 bandwidth 0.0 0.5 1.0 1.5 2.0 2.5