The OpenD Programming Language

geomDensity2D

Draw kernel density based on the x and y coordinates of the data

geomDensity2D
(
AES
)
(
AES aes
)

Examples

/// http://blackedder.github.io/ggplotd/images/density2D.png
import std.array : array;
import std.algorithm : map;
import std.conv : to;
import std.range : repeat, iota;
import std.random : uniform;

import ggplotd.aes : Aes;
import ggplotd.colour : colourGradient;
import ggplotd.colourspace : XYZ;
import ggplotd.geom : geomDensity2D;
import ggplotd.ggplotd : GGPlotD;
import ggplotd.legend : continuousLegend;

auto xs = iota(0,500,1).map!((x) => uniform(0.0,5)+uniform(0.0,5))
    .array;
auto ys = iota(0,500,1).map!((y) => uniform(0.5,1.5)+uniform(0.5,1.5))
    .array;
auto aes = Aes!(typeof(xs), "x", typeof(ys), "y")( xs, ys);
auto gg = GGPlotD().put( geomDensity2D( aes ) );
// Use a different colour scheme
gg.put( colourGradient!XYZ( "white-cornflowerBlue-crimson" ) );
gg.put(continuousLegend);

gg.save( "density2D.png" );

Meta