Gadfly: Enabling PublicationQuality Plotting with Julia
Visualisation of data in the form of plots is an important requirement in today’s Big Data scenario. This article introduces Gadfly – a visualisation system for Julia. Gadfly enables developers to build publication-quality graphics in various forms such a
Julia is becoming increasingly popular with developers from various domains, primarily due to the simplicity and power it offers. One important feature provided by most modern day programming languages is the ability to visualise data. As today’s applications handle large volumes of data, visualisation becomes a mandatory component.
Julia is an extensible programming language, i.e., its features can be extended by adding many custom packages. The external packages that facilitate plotting in Julia are listed below (http://julialang.org/ downloads/plotting.html):
PyPlot uses the Python calling feature (PyCall) to directly call MatPlotLib of Python. To use PyPlot in Julia programs, Python and MatPlotLib need to be available in the system.
The focus of this article is to illustrate the features of Gadfly, which is based on the Wickham-Wilkinson style ‘Grammar of Graphics’ in Julia. Detailed information on the Grammar of Graphics is available at https://www. cs.uic.edu/~wilkinson/TheGrammarOfGraphics/GOG. html. The ggplot2 for R forms the basis of Gadfly. Daniel C. Jones is the pioneer in developing Gadfly. An active community of Julia developers now maintains this package (https://github.com/GiovineItalia/Gadfly.jl).
Features of Gadfly
The major features of the Gadfly Julia package are listed below:
Gadfly has the important feature of rendering publication quality graphics. It enables rendering in various formats such as SVG, PostScript, PD, etc.
It offers support for 20+ plot types.
Gadfly is available in Julia, out-of-the-box.
The facility to integrate with DataFrames.jl is another key feature of GadFly. DataFrames.jl enables working with tabular data in Julia. It provides interactive features in plots such as panning, zooming, etc. These interactivity features are enabled through snap.svg (http://snapsvg.io/).
Installation of Gadfly can be easily done using the following command (at Julia REPL):
After successful installation, it can be loaded as shown below:
Julia> using Gadfly
Installing Gadfly Gadfly: A simple plot
Julia programs can be executed in two different ways—one is by installing Julia locally in the system and the other is to execute it directly in JuliaBox (https://juliabox.com/).
The steps involved in plotting a simple graph are illustrated in this section.
Step 1: Load the Gadfly package, as follows:
Step 2: Load the values in X and Y. In this example, we are loading 1000 random values in two variables— xvalues and yvalues.
xvalues = rand(1000) yvalues = rand(1000)
Step 3: Plot the graph with the Gadfly.plot function. Gadfly.plot(x=xvalues, y=yvalues, Geom.point)
The output of Step 3 is shown in Figure 2.
The following code sequence generates a line graph as shown in Figure 3: