What is a Butterfly chart?
A butterfly chart in Tableau is one of the important charts that helps to compare two sets of data from the dataset by highlighting their similarities and differences in an easier way to understand. This Butterfly Chart is also called the ‘Tornado Chart’.
Why it is named Butterfly Chart?
The visualization of this chart will have two sets of data on its side with a central axis in the middle. That is, one set of data is displayed on one side, whereas the other set is displayed on the other side of the chart. So, when the data spreads out on its side, it resembles a butterfly’s wings.
Why Butterfly Chart?
A butterfly chart is widely used to compare two groups to make the visualization clear and better. Also, the butterfly wing appearance of this chart helps to spot the differences between data points very easily.
When to use Butterfly Chart?
This chart is perfect to use when clear insight is needed between two sets of data as it displays the visual with bars on either side of a central axis in an effective way to get a better understanding. One of the best examples of a butterfly chart is displaying gender disparities in a dataset.
Now, let us see how this chart can be built to break down gender statistics for a particular scenario.
Use Case:
The use case I have taken is to analyze the male and female comparison in percentage based on the age bin for SIRS patients in Sepsis. Before that, let us understand what SIRS and Sepsis are.
Sepsis
Sepsis is a severe, inflammatory response to an infection that is caused by any type of infection, including
bacterial, fungal, or viral infections which can lead to organ dysfunction and even death due to a high mortality
rate if not diagnosed early.
SIRS
SIRS (Systemic Inflammatory Response Syndrome) is a life-threatening condition that occurs when the body's
immune system overreacts to an infection and other inflammatory triggers. It leads to serious complications, which lead to multiple organ failure and death. Early diagnosis and treatment are very important for such patients.
SIRS Criteria
A patient is classified as having SIRS if they meet two or more of the following signs
Body Temperature
Greater than 38.5°C or less than 35°C.
Heart Rate
Greater than 90 beats per minute.
Respiratory Rate
Greater than 20 breaths per minute, or a PaCO₂ level of less than 32 mmHg
White Blood Cell Count (WBC)
Greater than 12,000/µL, less than 4,000/µL, or greater than 10% immature (band) forms.
Dataset Used
For this analysis, I have used the 'Prediction of Sepsis' dataset. Let us dive into the analysis part now.
In the tableau, to get the SIRS patients, we need to write a calculation based on the above SIRS criteria. The biomarkers to be considered to get SIRS patients are Temperature, Heart Rate, Respiratory Rate, PaCo2 and WBC. When at least two or more of these biomarker ranges go below or above the level for any patient, they are likely to be considered SIRS patients.
Now, let us see the calculations used for this analysis. To write a calculation in the tableau, click the dropdown next to search option in the data pane section and choose 'Create Calculated Field'.
Getting SIRS Patients using calculation
SIRS patients - write a calculation to get SIRS patients based on the given criteria as in the screenshot below
Getting Male and Female patients count using calculation
For that, create a calculated field 'Gender_Range' to identify the male and female patients from the overall patients in the dataset. In this dataset, label has been given for Male / Female gender. For females, the label is '0' and for males, the label is '1'.
Now, using the above calculation, ‘Gender_Range’, let us get the count of female SIRS patients
with the calculated field name as ‘FemalePatients’.
Now, using the above calculation, ‘Gender_Range’, let us get the count of male SIRS patients
with the calculated field name as ‘MalePatients’.
In the above calculations, we get the male and female SIRS patients. Now, Calculations are needed to get the Count of Male and Female patients separately.
To get the female count, write a calculation as in the screenshot below. The name I have given for getting the female count is ‘Count of SIRS Female.’
To get the male count, write a calculation as in the screenshot below. The name I have given for getting the
male count is ‘Count of SIRS Male.’
Creating Age Bin
Now, the age bin has to be set up. When you right-click the Age field, click ‘Create’ and choose ‘Bin’ from the drop-down. Then, the following screen appears. Here, I have used the age bin 10, as you can see in the screenshot below.
A separate field ‘Age(bin)’ will be created in the data pane after this step.
Creating a calculating field for 'Zero Axes'
Now, create a calculation field as ‘Zero Axes’, which needs to be created for having the axis in the center between two groups or data in the butterfly chart. In the calculation field, just type ‘0’ and click ‘Ok’ as you can see in the screenshot below
Now let us see a step-by-step guide for building a butterfly chart.
Step 1:
Drag the ‘FemalePatients’ calculated field to columns and change the measure to Count Distinct.
Then drag the ‘Zero Axes’ calculated field into columns.
Drag the ‘MalePatients' calculated field to columns and change the measure to Count Distinct.
The sheet will look like the following screenshot.
Step 2:
Now drag ‘Age(bin)’ to Rows. The screen will appear like the following screenshot.
Step: 3
Now, on the left data pane, under the Marks section, change the Zero Axes type into ‘Text’ (by default it will be showing as Bar type.) Then drag the ‘Age(bin)’ to label. Then the screen of the sheet will appear as follows.
Step: 4
Now, remove the ‘header’ on the left axis by clicking the 'Show Header' option, as we already have the age bin showing in the center axis (Zero Axes).
Step: 5
Now, change the names on both sides of the zero axes for females and males. First, right-click on the female side axis and choose the ‘Edit Axis’ option, as you see in the screenshot below.
Now, a pop-up screen appears as you see in the screenshot below. In that, under ‘Scale,’ check the ‘Reversed’ option and give a proper title for 'Female' side axis.
And then go the next tab ‘Tick Marks’ in the same pop-up screen and select ‘None’ as seen below.
Step: 6
Now, right click on the 'Male' side axis and click 'Edit Axis' option and just give an appropriate title for male side axis under 'General' tab and choose none under 'Tick Marks' tab as you see in the screenshot below
Step: 7
Now, it’s time to edit the axis in Zero Axes. Right-click on the Zero Axes and choose the ‘Edit Axis’ option.
Then, give an appropriate title. Here, I have given the name ‘Age Bin’ as we are going to show the age category in the center and choose 'none' option under 'Tick Marks' tab.
Step: 8
Now, change the view size of the chart. By default, in tableau, charts would be in Standard mode. We need to change it to 'Entire View' so that the chart will become bigger and visible than before
Now, right-click on any number in the chart, select ‘Format’ and then edit the size of the numbers(as needed), and make the necessary changes to make the font in the chart visible. Also, give a proper title for this chart based on the analysis. After making the necessary changes, the screen will appear as follows.
Step: 9
Now, go to the ‘Female count’ under the Marks section in the left data pane, and drag the ‘Count of SIRS female’ calculated field to label and give color to the 'female' data. For females, I have chosen Pink color.
Then, follow the same steps for the Male count as well, and drag the ‘Count of SIRS Male’ calculated field to label and give color to the 'male' data. For Males, I have chosen Blue color. The chart should appear as follows.
Step: 10
The above chart displays the count of female and male patients under SIRS criteria. To display the count in percentage, right-click the label in the Marks section. In the drop-down menu, select the ‘Quick Table Calculation’ and choose the ‘Percent of Total’ option.
Then, the chart displays the male and female percentage of SIRS patients. The chart will appear like in the screenshot below.
In the above chart, it is visible that, at the age of 60, male patients are more than female patients under SIRS criteria, and at the age of 30, female patients are more than male patients.
Conclusion
As I mentioned above in this blog, a butterfly chart provides an effective way to compare gender dynamics in a dataset. By visualizing bars on either side of a central axis, it becomes easier to identify patterns, disparities, or trends at a glance.
Thank you for reading this blog..
Note : The link for the dataset I have used for the analysis in this blog is as follows