π Hi!
You're now more than 9000 people reading this newsletter π±. Thank you so much! πππ
β
If you want to share it with a friend, I just put together a (for now, ugly) homepage with all past issues.
As always, todayβs tip is short but powerful. Letβs talk aboutβ¦
β
The problem with legends
Most dataviz libraries make it easy to add legends. That's great! Sometimes, theyβre essential for understanding a chart.
But most of the time? Legends are a hassle.
Take this stacked area chart, for example:
β
β
β
Reading it means constantly jumping back and forth between the chart and the legend. What does this color mean? Check the legend. What about this one? Check again. And again. π³
Thatβs a lot of unnecessary cognitive load. Instead of absorbing the story, your audience will struggle just to decode the chart. Youβll lose their attention.
So hereβs my advice: If you can remove the legend, remove it.
β
Solution 1: Direct labeling
Instead of using a separate legend, label the groups directly on the chart.
Line charts / Stacked area charts? Place the labels near the end of the lines. Scatterplots? Find a good spot near the groupβs center. Streamgraphs? Position labels inside the flow where they fit naturally.
Here is an example we've built for the Python Graph Gallery:
β
You see a group, and know instantly what it is! This takes extra effort, but trust me: your readers will thank you.
Technical tip:β
In R, the ggrepel package helps position labels without overlap. In Python, check out drawarrow for easy annotation with arrows.
β
β
βSolution 2: Color in the title
That's another solution: use colors in the title to highlight key categories.
β
This way, you deliver the main message and introduce the groups in one go.
β
Cedric Scherer uses this technique very often. Here is an example with a dumbbell chart from the r graph gallery:
β
β
β
Takeaway
Whenever possible, ditch the legend to make your chart easier to read.
Still skeptical? Check out Dataviz-inspiration.com. Youβll notice that most top-tier visualizations use direct annotation, not legends.
Hope this helps and see you next week!
β
Yan
β
βPS: this post is a short abstract from the 3rd module of Matplotlib Journey. We just shipped it, and the course is now almost complete π
β
βPPS: I'm working on a tool allowing to create a homepage like mine in less than 30 minutes. Would you like to beta-test it? Hit reply!
β
π By the way, here is how I can help!
β
- Master R: Join my productive R workflow online course, already helping hundreds to excel in R, Quarto, and GitHub.
- Team Training: Hire me to train your team on Data Visualization and Programming.
- Engaging Talks: Book me for short, impactful talks on Data Visualization and Programming.
β
Check yan-holtz.com or hit reply any time! I love hearing from you.
|
β
β
β
β
β
|
β