21
2016
How to create Radial Bar Charts in Tableau
This article explains how to create a radial bar chart in Tableau.
Theory/Information:
Radial bar chart is a variation of a pie. Like a pie chart, a radial bar chart shows the relationship of parts to a whole, but a radial bar chart can contain sub categories for each part of the whole. Each category in the data series that is being plotted in a radial bar chart, gets a different color and all the subcategories are given the same color.
When do we use a radial bar chart?
Consider using a radial bar chart when:
- There is a hierarchy in the data – For example, product category and product sub-category
- None of the values to be plotted is negative or zero
- Not more than 7 categories are present per data series
- Categories represent parts of a whole in each ring
Pre-Requisites:
Before we start with the steps to create a radial bar chart, we need to go back to our school days and dust our knowledge on trigonometry and geometry.
Consider the image below. The Green line is what we want to plot on the arc or circle. Basically, we need to identify a starting and ending point for each of the measure values, so that they can be plotted between the points on the circle.
Let us decide on the radii for the inner and outer circle. The radii of the circles can be decided based on the number of measures that needs to be plotted as bars on the circle. As the number of measures decreases, we can reduce the radii.
After deciding the radii of the 2 circles, we need to decide on the angle at which the measures will be plotted. In a circle, the total angle is 360 degrees or 2 PI radians. Hence, if ‘N’ is the number of observations or bars that need to be plotted on the circle, the angle for each bar will be x = (2 * PI)/N. We need to multiply the obtained angle, x, by an index or running number for each bar, so that we get consecutive angle values, at which to draw the bars. If y is the final angle for each bar, we can calculate y as (Index * (2 * PI)/N).
Before we use the angle to find the coordinates of the starting and ending points of each bar, we need to assign normalized lengths to all the bars.
Usually, to normalize any value, the formula used is:
X’ = (X / Max(X)) * (Max(X) – Min(X))
In this case, the formula for the normalized length becomes:
Normalized Length = [Measure]/Max([Measure]) * (Outer Radius – Inner Radius)
Now, back to trigonometry. We all know that the x and y coordinates for any point on a circle can be obtained if we know the radius of the circle and the angle at which the point is present. For the starting point of any measure the radius to be considered will be that of the inner circle, say r1, and the radius for the ending point of the measure is that of the outer circle, say r2.
The x and y coordinates of a point is obtained as cos Ө and sin Ө respectively, where Ө is the angle.
Therefore, the starting point is calculated as follows:
[x1,y1] = [ l1*cos Ө, l1*sin Ө ]
and the ending point is calculated as:
[x2,y2] = [ l2*cos Ө, l2*sin Ө ]
where l1 and l2 are the normalized lengths. L1 will always be zero as it is the starting point of the bar.
Steps to create a radial bar chart in Tableau:
The following steps demonstrate how a radial bar chart can be created from the Sample – Superstore database, which comes along with Tableau.
Step 1:
First, we need to get the data ready. The original data that needs to be plotted has to be duplicated. Introduce an additional field, PathOrder, which holds 1 for one set of the data and 0 for the duplicate of the same data. The sample data is attached below.
Following is the query to obtain the data:
SELECT [Orders$].[Product Category] AS [Category],
[Orders$].[Product Name] AS [Item],
[Orders$].[Profit] AS [Profit],
[Orders$].[Row ID] AS [Row ID],
[Orders$].[Sales] AS [Sales],
1 AS PathOrder
FROM [Orders$]
UNION ALL
SELECT [Orders$].[Product Category] AS [Category],
[Orders$].[Product Name] AS [Item],
0 AS [Profit],
[Orders$].[Row ID] AS [Row ID],
0 AS [Sales],
0 AS PathOrder
FROM [Orders$]
Step 2:
Once the data is ready, we need to create some calculated fields. For each data point, we need to figure out the angle for each bar, the coordinates of the data point and also a normalized length for each bar. We basically need 2 circles – 1 inner circle and 1 outer circle – between which the bars will be drawn. We will set the outer radius to be 1 and the inner radius to be 0.2. If required, the inner and outer radii can be provided as a parameter, to make it dynamic.
Let’s create the calculated fields:
Step 3:
We need to combine the ‘Category’ and ‘Item’ fields to create a combined field on which we can perform all the calculations. Click Category then Ctrl+Click Item and right-click and select Combine Fields.
Step 4:
Let’s start creating the chart now.
- Add RADIAL_X to Columns and RADIAL_Y to Rows
- Choose Line as the mark type on the Marks card
- Add Category to Color on the Marks Card
- Add the combined field(Category&Item) on to Detail on the Marks card
- Add PathOrder to Path on the Marks Card
- For RADIAL_X and RADIAL_Y, set the table calculation to Compute Using Category&Item
- Edit the axes so that the range is fixed from -1 to 1
Step 5:
The radial bar chart is ready. We can change the size of the bars, on the circle, by changing the size slider on the Marks card. Also, format the chart to remove the Gridlines and zero lines.
Inspired by Interworks
[…] let’s create the following calculated fields. I’ve adapted them a bit from this blog on radial bar charts so that you can put the X field on columns and the Y field on rows, which is more […]