Gadfly is a system for plotting and visualization based largely on Hadley Wickhams's ggplot2 for R, and Leland Wilkinson's book The Grammar of Graphics.
From the Julia REPL a reasonably up to date version can be installed with
In [ ]:
#Pkg.add("Gadfly") # Note: already installed in this demo.
This will likely result in half a dozen or so other packages also being installed.
Gadfly is then loaded with
In [1]:
using Gadfly
Most interaction with Gadfly is through the plot function. Plots are described
by binding data to aesthetics, and specifying a number of plot elements
including scales, coordinates, guides, and geometries.
Aesthetics are a set of special named variables that are mapped to plot
geometry. How this mapping occurs is defined by the plot elements.
This "grammar of graphics" approach tries to avoid arcane incantations and special cases, instead approaching the problem as if one were drawing a wiring diagram: data is connected to aesthetics, which act as input leads, and elements, each self-contained with well-defined inputs and outputs, are connected and combined to produce the desired result.
If no plot elements are defined, point geometry is added by default. The point
geometry takes as input the x and y aesthetics. So all that's needed to draw
a scatterplot is to bind x and y.
In [7]:
plot(x=rand(10), y=rand(10))
Out[7]:
Multiple elements can use the same aesthetics to produce different output. Here the point and line geometries act on the same data and their results are layered.
In [8]:
# E.g.
plot(x=rand(10), y=rand(10), Geom.point, Geom.line)
Out[8]:
More complex plots can be produced by combining elements.
In [9]:
# E.g.
plot(x=1:40, y=2.^rand(40),
Scale.y_sqrt, Geom.point, Geom.smooth,
Guide.xlabel("Stimulus"), Guide.ylabel("Response"), Guide.title("Dog Training"))
Out[9]: