The OpenD Programming Language

GGPlotD

GGPlotD contains the needed information to create a plot

Members

Functions

colourGradient
ColourGradientFunction colourGradient()

Active colourGradient

drawToSurface
cairo.Surface drawToSurface(cairo.Surface surface, int width, int height)

Draw the plot to a cairoD cairo surface.

drawToSurface
auto drawToSurface(gtkdSurface.Surface surface, int width, int height)

Draw the plot to a GtkD cairo surface.

margins
Margins margins(int width, int height)

Active margins

opBinary
GGPlotD opBinary(T rhs)

Using + to extend the plot for compatibility to ggplot2 in R

put
GGPlotD put(T rhs)

put/add to the plot

save
void save(string fname, int width, int height)

save the plot to a file

scale
ScaleType scale()

Active scale

Examples

import std.range : zip;
import std.algorithm : map;

import ggplotd.aes : aes;
import ggplotd.geom : geomLine;
import ggplotd.scale : scale;
auto gg = zip(["a", "b", "c", "b"], ["x", "y", "y", "x"], ["b", "b", "b", "b"])
    .map!((a) => aes!("x", "y", "colour")(a[0], a[1], a[2]))
    .geomLine
    .putIn(GGPlotD());
gg + scale();
gg.save( "test6.png");
// http://blackedder.github.io/ggplotd/images/noise.png
import std.array : array;
import std.math : sqrt;
import std.algorithm : map;
import std.range : zip, iota;
import std.random : uniform;

import ggplotd.aes : aes;
import ggplotd.geom : geomLine, geomPoint;
// Generate some noisy data with reducing width
auto f = (double x) { return x/(1+x); };
auto width = (double x) { return sqrt(0.1/(1+x)); };
auto xs = iota( 0, 10, 0.1 ).array;

auto ysfit = xs.map!((x) => f(x));
auto ysnoise = xs.map!((x) => f(x) + uniform(-width(x),width(x))).array;

auto gg = xs.zip(ysnoise)
    .map!((a) => aes!("x", "y", "colour")(a[0], a[1], "a"))
    .geomPoint
    .putIn(GGPlotD());

gg = xs.zip(ysfit).map!((a) => aes!("x", "y")(a[0], a[1])).geomLine.putIn(gg);

//
auto ys2fit = xs.map!((x) => 1-f(x));
auto ys2noise = xs.map!((x) => 1-f(x) + uniform(-width(x),width(x))).array;

gg = xs.zip(ys2fit).map!((a) => aes!("x", "y")(a[0], a[1]))
    .geomLine
    .putIn(gg);
gg = xs.zip(ys2noise)
    .map!((a) => aes!("x", "y", "colour")(a[0], a[1], "b"))
    .geomPoint
    .putIn(gg);

gg.save( "noise.png" );
// http://blackedder.github.io/ggplotd/images/hist.png
import std.array : array;
import std.algorithm : map;
import std.range : iota, zip;
import std.random : uniform;

import ggplotd.aes : aes;
import ggplotd.geom : geomHist, geomPoint;
import ggplotd.range : mergeRange;

auto xs = iota(0,25,1).map!((x) => uniform(0.0,5)+uniform(0.0,5)).array;
auto gg = xs
    .map!((a) => aes!("x")(a))
    .geomHist
    .putIn(GGPlotD());

gg = xs.map!((a) => aes!("x", "y")(a, 0.0))
    .geomPoint
    .putIn(gg);

gg.save( "hist.png" );

Setting background colour

/// http://blackedder.github.io/ggplotd/images/background.svg
import std.range : zip;
import std.algorithm : map;
import ggplotd.aes : aes;
import ggplotd.theme : background;
import ggplotd.geom : geomPoint;

// http://blackedder.github.io/ggplotd/images/polygon.png
auto gg = zip([1, 0, 0.0], [1, 1, 0.0], [1, 0.1, 0])
    .map!((a) => aes!("x", "y", "colour")(a[0], a[1], a[2]))
    .geomPoint
    .putIn(GGPlotD());
gg.put(background(RGBA(0.7, 0.7, 0.7, 1)));
gg.save( "background.svg" );

Other data type

/// http://blackedder.github.io/ggplotd/images/data.png
import std.array : array;
import std.math : sqrt;
import std.algorithm : map;
import std.range : iota;
import std.random : uniform;

import ggplotd.geom : geomPoint;

struct Point { double x; double y; }
// Generate some noisy data with reducing width
auto f = (double x) { return x/(1+x); };
auto width = (double x) { return sqrt(0.1/(1+x)); };
immutable xs = iota( 0, 10, 0.1 ).array;

auto points = xs.map!((x) => Point(x,
    f(x) + uniform(-width(x),width(x))));

auto gg = GGPlotD().put( geomPoint( points ) );

gg.save( "data.png" );

Meta