public struct GGPlotD

GGPlotD contains the needed information to create a plot

Example

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");

Example

// 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" );

Example

// 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" );

Example

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" );

Example

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" );

public ref cairo.Surface drawToSurface(
    ref cairo.Surface surface, 
    int width, 
    int height) const

Draw the plot to a cairoD cairo surface.

Parameters

surface

Surface object of type cairo.Surface from cairoD library, on top of which this plot is drawn.

width

Width of the given surface.

height

Height of the given surface.

Returns

Resulting surface of the same type as input surface, with this plot drawn on top of it.
public auto drawToSurface(
    ref gtkdSurface.Surface surface, 
    int width, 
    int height) const

Draw the plot to a GtkD cairo surface.

Parameters

surface

Surface object of type cairo.Surface from GtkD library, on top of which this plot is drawn.

width

Width of the given surface.

height

Height of the given surface.

Returns

Resulting surface of the same type as input surface, with this plot drawn on top of it.
public void save(
    string fname, 
    int width = 470, 
    int height = 470) const

save the plot to a file

public ref GGPlotD opBinary(string op, T)(T rhs) 
if(op == "+")

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

public ref GGPlotD put(T)(T rhs)

put/add to the plot

public ScaleType scale() const

Active scale

public ColourGradientFunction colourGradient() const

Active colourGradient

public Margins margins(
    int width, 
    int height) const

Active margins

Functions

refdrawToSurfaceconst

Draw the plot to a cairoD cairo surface.

autodrawToSurfaceconst

Draw the plot to a GtkD cairo surface.

saveconst

save the plot to a file

refopBinary

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

refput

put/add to the plot

scaleconst

Active scale

colourGradientconst

Active colourGradient

marginsconst

Active margins