Double, Spaced Doughnut Chart: UK Election 2017 6


Facebooktwittergoogle_pluspinterestlinkedinmailFacebooktwittergoogle_pluspinterestlinkedinmail

Election2017

After the United Kingdom 2017 General Election, on Thursday 8th June 2017, I had many conservations about our First Past The Post system (FPTP), and why we do not have a Proportional Representation (PR).

In the UK FPTP system, we have 650 individual battlegrounds, each representing one seat, the party with the most seats wins. This means that a party could technically score second place in every battle but have zero seats in Parliament.

In this tutorial, we will walk through the creation of spaces doughnut charts in Tableau.

The Data

The source for our data is the British Broadcasting Corporation, otherwise known as the BBC: http://www.bbc.co.uk/news/election/2017/results

I have prepared and put this data into a text file that you can download: HERE

Calculated Fields

We will create a Path (bin) object by:

  • Right click on Path
  • Go to Create, Bins…
  • In Edit [Path] set the Size of bins to 1
  • Click Ok

SpacedDoughnut1

The Path (bin) will allow us to use a table calculation to create additional data points between 1 and 360.

Note: we are using the Path (bin) to densificate date and give us more points to work with. One thing to make sure of is that you check the Show Missing Values.

We will now need to create the following Calculated fields:

Center Text Position: This will be used to position our text in the centre of the Doughnut.

SpacedDoughnut2

Index: returns the index of the current row within a partition. Index starts are 1 but we want our index to start at 0 so we subtract 1.

SpacedDoughnut3

WC_PI: To be able to multiple our Index (based on the bin object) by PI we will need to create a Table Calculation to represent PI.

SpacedDoughnut4

Seat Share: This calculated field will be used for the text at the centre of the Doughnut chart to represent the Seat Share, as a percentage.

SpacedDoughnut5

Vote Share: This calculated field will be used for the text at the centre of the Doughnut chart to represent the Seat Share, as a percentage.

SpacedDoughnut6

WC_Position: This calculated field will give the distance from the centre of the Doughnut.

SpacedDoughnut7

WC_Value: This will give value. Either Percentage of Seats of Percentage of Votes.

SpacedDoughnut8

X: As we are drawing the polygons we need an X point.

SpacedDoughnut9

Y: As we are drawing the polygons we need an Y point.

SpacedDoughnut10

Note: the COS and SIN function requires the values in Radians as opposed to degrees. To convert Degrees to Radians we need to multiply by PI and divide by 180.

Color: This is used to give our bars the colour based on the value of the percentage values.

SpacedDoughnut11

Worksheet

Let’s start by adding the following objects to our worksheet.

  • Drag Party onto Columns
  • Drag Path (bin) onto Details
    • Make sure the Path (Bin) object has Show Missing Values selected
    • If in doubt drag the object onto Rows and then right click to check.
  • Drag Type onto Details
  • Drag Party onto Details
  • Turn the Mark Type to Line
    • Drag Position on Path
    • Make sure the Position is a Discrete Dimension
  • Drag Party onto Filters and choose Conservatives
    • This will make things easier to work with for now.
  • Drag Y onto Columns
    • Right click on the object, selection Compute Using and then Path (Bin)
  • Drag X onto Rows
    • Right click on the object, selection Compute Using and then Path (Bin)

You should now see the following:

SpacedDoughnut12

Excited yet? I sure am, but let us add some colour add formatting to this.

  • Drag Color on the Color Marks
    • Right Click on the object, selection Compute Using and then Path (Bin)
  • Right click on the background and remove the:
    • Gridlines
    • Zero Lines
    • Hide the X and Y Axis

You should now have the following:

SpacedDoughnut13

We will now complete the Doughnut and add some text to the centre.

  • Drag Center Text Position onto Rows
    • Right click and select Dual Axis
    • Right click on the axis bar and select Synchronize Axis
  • You should have AGG(Center Text Position) as an option on Marks
    • Remove all objects
    • Change the Marks to Text
    • Drag Seat Share to Text
    • Drag Vote Share to Text
    • Right Click on Seat Share and Vote Share and change the Number format to 1 decimal place percentage.
    • Click on the Text and edit as you please.

Note: Make sure you go to the X object in Marks and removes the Measure Names, i this has been added.

Finishing

Now play around with the Party in the Filter Pane, edit Colors for the various parties, adjust the value of Center Text Position, resize as needed, and you should end up with something like the following:

SpacedDoughnut14

…and that is a wrap.

I hope you enjoyed this blog and please, please, please, do leave me a comment below and message me on twitter @thoang1000 is you have any issues.

I am completing a book on fun stuff with Tableau where we will go into more depth understand the various techniques in depth. I hope you check it out and find it useful.

Facebooktwittergoogle_pluspinterestlinkedinmailFacebooktwittergoogle_pluspinterestlinkedinmail

Toan Hoang

About Toan Hoang

Toan Hoang is a technology enthusiast with a broad understanding and appreciation of most aspects of technology but with a passion for Business Intelligence Solutions and Technologies, Data Management and Web Programming.


Leave a comment

Your email address will not be published. Required fields are marked *

6 thoughts on “Double, Spaced Doughnut Chart: UK Election 2017