Awesome Plotly with code series (Part 3): Highlighting bars in the long tails
Who said that the longer tails are not important? Let's give them a proper way to stand out.
Welcome to the third post in my “Plotly with code” series! If you missed the first one, you can check it out in the link below, or browse through my “one post to rule them all” to follow along with the entire series or other topics I have previously written about.
A short summary on why am I writing this series
My go-to tool for creating visualisations is Plotly. It’s incredibly intuitive, from layering traces to adding interactivity. However, whilst Plotly excels at functionality, it doesn’t come with a “data journalism” template that offers polished charts right out of the box.
That’s where this series comes in — I’ll be sharing how to transform Plotly’s charts into sleek, professional-grade charts that meet data journalism standards.
A small but really important bar
When someone thinks about bar charts, they often think about tangible and easy to detect bars. But, what about the underdog, the little bar that quietly sits at the end of the lineup? Sure, it may have a low value, but it can tell a compelling story.
However, highlighting such a small bar when it is surrounded by bigger bars and numbers, can be difficult. In this post, I’ll show you how to give that small but mighty bar the spotlight it deserves using Plotly. After all, in data visualisation, it’s not just about the size; it’s about the significance!
What will we cover in this blog?
You will see how colouring these small bars is not enough.
You will see how we can use the concept of “highlighting” to make these bars stand out.
PS: As always, code and links to my GitHub repository will be provided along the way. Let’s get started!
Colouring bars is not enough
In my previous post Awesome Plotly with code series (Part 2): Colouring bar charts, we covered how we could use colour contrast to get the reader to focus on a specific area of the bar chart. However, that was under the assumption that there was a big enough bar to actually see the colour contrast.
Imagine that we are looking at a series of data where lower numbers are actually the best possible outcome. For instance, during Covid, having a low death rate per 100k patients was the goal. Most countries in the world suffered having high numbers on this metric, except a few countries, for example, China. This is what the data looks like.
You will see later what the bars look like, but you can see in the default plot below how tiny is the China and New Zealand bar compared to the Brazil bar. Brazil had a 200x death rate compared to China!!
Theory: colour contrast should be useful, but how do we use it?
Colour contrast is a pre-attentive visual attribute. The human brain is wired to immediately pick out differences in our environment. For bar charts, our brains would try to naturally compare the size and the colour of the bars. Therefore, by using a different colour for China and New Zealand, we should direct the readers attention directly to their respective bars.
BUT, if the bars are small enough, it doesn’t matter how you colour them. Your brain will try to focus on differences for the bars it can detect. For example, it will look at Brazil vs France.
The first attempt — Colour the small bars
Keep reading with a 7-day free trial
Subscribe to Senior Data Science Lead to keep reading this post and get 7 days of free access to the full post archives.