A collection of charts types, with usage advice and links to data and code.
Line charts
One line | CSV data
The simplest line chart, running from data stored in my GitHub repository.
One line | API data
A single line, running live from the new Economics Observatory API.
Many lines | Long Form
This chart uses "long form" data, which is the ideal format if working with csv files. The spec also uses a transform to remove some G7 nations so that the chart is not too cluttered. By playing with the transform you can add/remove countries.
Many lines | Wide Form
This chart uses "wide form" data, which is familiar from Excel. It is a little more complex to use in most visualisation libraries.
Many lines | Multiple sources
Some APIs return only one series. This chart runs from JSON data from the new Economics Observatory API, and uses "layers" to add each country. Each "layer" uses "calculate" to add the country name to each set of country data. It is in effect three charts, one for each country, overlaid on one another.
Lines with two y-axes
When plotting two lines with very different scales is may be helpful to separate the y dimesion for each line.
Highlighting most recent data
Adding a point and the data value to the most recent data point. This uses a layer, which finds the maximum value of the data series, and puts both the point and the value at the max. This ensures the chart is responsive, so the location of the point and value both update when the data refreshes.
Two lines: filled range
A useful chart to demonstrate the varying distance between series, in this case the Bitcoin high and low trading price.
Interactive line: data selector
This chart uses a very long run of data, allowing users to focus on a particular period using the sliders.
Line with tooltip
A simple line chart with a tooltip that moves along the series as the user hovers.
Re-based data (wide form)
An example of which transposes the data, rebasing so that 1980=100.
Wide form data, folded to long form
Turing wide data into long form to allow easy use of the facet encoding.
Interactive: sliders
This spec creates a year variable from dateTime data (yyyy-mm-dd), adds sliders that return a year value, and then filters the data based on the years picked using the sliders.
ONS, CORS mend
Simple line chart with CORS mended, generic set up for ONS charts.
Bar charts
Simple vertical bar chart
This is a straightforward bar chart that plots a y variable against an x variable. In this case, the x variable is the year and the y variable is the share of green seats in the European parliament.
Simple horizontal bar chart
By flipping the x and y variables in the code, it is possible to plot a horizontal bar chart.
Stacked vertical bar chart
Stacked bar charts are useful when there are a number of components that make up a given value. For example, here we split food emissions up by each stage in the production process.
Stacked horizontal bar chart
Using the same flip trick, we can create a horizontal version of the stacked chart.
Grouped vertical bar chart
In the case where several variables are being displayed in distinct clusters, grouped bar charts are useful. In this example, GDP growth for all four UK nations are displayed per quarter, allowing the reader to easily compare each country.
Layered bar chart
Layer commands can be useful when more than one piece of information is being conveyed. In this case, the simple veritcal bar chart shows the number of products at each sugar intensity. The line tracks the tax rate. Two distinct y axes provide the values.
Interactive bar chart | Tooltip
Adding a tooltip allows the reader to see underlying values by hovering their mouse over the bars. This is one of the main advantages of building charts live in the page (as opposed to using image files).
Scatter and bubble
Scatter: 5 variables.
This chart takes variables to the extreme: there is probably too much going on here for it to be useful, but worth knowing it is possible.
Football scatter: tooltip and number format.
This chart includes a tooltip - hover over the dots to see the countries. The numbers in the tooltip are formatted to make them nicer to read. Based on an idea by Vikram Rajendran
Area charts
Area | Data transform | Custom labels
An area chart on global debt. The spec includes a transform of wide to long-form data, and custom labels.
Area | Interactive | Click legend
Adding interactivity by allowing the user to click on the legend to highlight the series they are interested in.
Area | Distributions
Swathe charts are a type of area chart with the first series set to have the same colour as the background.
Interactive charts
Interactive | Year Selector
In this chart the user selects the start and end year. The key addition is the "Params" encoding.
Interactive | Colour Selector
A demonstration of the how users can pick a parameter. In this case the colour of the line.
Class examples
Class | Glasgow Effect
A boring chart that you might want to edit in some way, without distoriting it.
Class | Gender Parity 1
A set of examples on gender parity. By Josh Hellings, based on an original idea by Alan Smith. The chart starts off with this uninspiring and hard to read bar chart - what is the message here?
Class | Gender Parity 2
A simple improvment is to flip the axes, so that country names can be read. In general bar charts with long names look better this way, that by using diagonal or offset labels on a vertial bar chart.
Class | Gender Parity 3
Since we have a clear policy and logical rationale we can rebase the data. The sensible comparison here is 1, which represents complete equality. How far are countries from this goal. This spec tells us.
Class | Gender Parity 4
Adding some nicer colours, conditional on the data being within or outside the target range.
Class | Gender Parity 5
Now we add some custom labelling, recall that this is one of Tufte's 6 principles
Class | Gender Parity 6
Finally, we place the country names close to the axis. Compare this to example 1. The same data, but a much clearer story.
Class | Anscombe 1
A dataset here which co-mingles various difference policies - what can we do to clear this up?
Class | Anscombe 2 | Filter
One option is to filter the data, so that only data from one policy experiment is showing.
Class | Anscombe 3 | Colour
Another option is to use colour. In this case it is not very helpful...
Class | Anscombe 4 | Facet
The facet encoding produces a grid of charts. In this case, this is much clearer.
Class | Anscombe 5 | Non-Bertin
This example violates Bertin's rules that we dicuss in class. A nominal variable is used as the x position encoding; and a quantitative variable is used as the colour encoding.
Class | Tidy Data 1 |
This example takes in spreadsheet style "wide" data. The transform converts this to tiday (AKA long-form) data. The chart does not work well, given the differences in currencies used.
Class | Tidy Data 2 |
With data in tiday form we can easily change or spec so that we use a "facet" encoding to provide a trelliss style chart. The main complication is that we must use independent y axes to display the data well.
By Richard Davies