Edward Tufte’s famous book “The Visual Display of Quantitative Information” contains a section in which he redesigns the classic bar chart in a way that leaves exactly the ink necessary to convey the desired information. In this post, I’ll show how to replicate his visually-pleasing bar chart in Julia using the Gadfly graphing package.
Here’s what we’ll make.
For reference, Tufte’s redesign is shown below.
Bar charts in Julia using Gadfly
Gadfly is an awesome Julia package that I have been using recently to produce the majority of my scientific visualizations. It is based on Leland Wilkinson’s book The Grammar of Graphics and Hadley Wickhams’s ggplot2 for the R programming language. By default it produces some pretty nice bar charts, but also provides many opportunities for customization.
Customizing Gadfly using Themes
Gadfly allows customization of a number of its components using Theme objects. We’ll define a Theme that modifies the bar color, background color, spacing between bars, and typefaces, and also eliminates the plot’s grid lines. More about customization using Themes can be found in the Gadfly Theme Documentation.
Customizing axes using Guides
Using Themes got us a lot of the way there, but our bar chart is still cluttered by a lot of unnecessary axis elements. We now use Gadfly’s Guides and Coords to remove some of the default axis elements. Here is the Gadfly Guides Documentation and the Gadfly Coords Documentation.
Adding a baseline and grid lines using annotations
Finally, we would like to include the baseline and grid lines from Tufte’s bar chart. To do this, we will use Guide.annotation to place annotations consisting of a Compose graphic. Compose is a vector graphics system for Julia, that forms the basis of Gadfly. Guide.annotation can be used to place arbitrary Compose elements into Gadfly plots. Here is the Compose Package Documentation along with the Guide.annotation Documentation.
There we go!
Visualizing my TA ratings
We can now use what we created to visualize a data set. Here are the student ratings of my teaching as a TA for EE 120: Signals and Systems at UC Berkeley in the Fall 2015 semester.