Understanding Letter Value Plot and Boxenplot | Towards Data Science

On top of this, boxplots are not easy to understand for everybody. That’s why data scientists often earn reactions like this when presenting boxplots to other people in the business:
But help is here! Boxenplots (or letter-value plots) are an advancement of boxplots, designed to visualize distributions more accurately. And in my experience, these charts are much easier to interpret for stakeholders too.
In this post, I explain why boxenplots can be a massive improvement over boxplots using a practical example.
Let’s have a quick look at why we use boxplots in the first place. Boxplots are a handy tool to get a quick overview of the distribution of a dataset. They allow to check:
If and how your data is skewed
How your data is grouped
How outliers are spread
Have a look at the following boxplot that depicts the distribution of the tip customers gave in a restaurant:
We can immediately draw a few conclusions from this:
The tip is usually below 14$; everything above is considered an outlier
In 75% of all cases, the tip is smaller than 8.6$ (3rd Quantile)
50% of customers gave at least 5.8$ (Median)
There are some outliers where customers tipped up to 29$
Pretty useful, isn’t it?
Boxplots are great to have a quick summary of the underlying data. But using this kind of data visualization also has some disadvantages.
Unfortunately, boxplots are not great when dealing with large datasets. To understand this, let’s have a quick look at the mechanics behind boxplots.
With boxplots, one can summarize the distribution of a dataset with a handful of figures like the median, the 25th percentile or the minimum. If you have a look at the image above, you can see that those numbers correspond to specific areas of the dataset’s probability density function (PDF).
Integrating over these areas gives us the probability that a random number from the dataset falls into these ranges. So in case of a normal distribution, the interquartile range (IQR) accounts for 50% of our data.
As a result, outliers always account for 0.7%, no matter how big our dataset is. If we had a dataset with 100.000 rows, we’d have 700 outliers in our boxplot that would only be depicted as a cloud of black dots:
But sometimes those data points can be particularly interesting. The range of outliers in the image above ranges from 14$ up to 29$. Wouldn’t it be interesting to know more about the distribution of tips in this range?
At the same time, it is questionable whether tips around 14$ are indeed outliers. They might be extreme compared to the rest of the tips given by customers, but not unexpected. Hence having a hard threshold of 0.7% of data points being outliers becomes a problem when dealing with large datasets.
Furthermore, boxplots are not that intuitive to interpret. In my experience, stakeholders usually have heard of boxplots but can’t remember what the different boxes and whiskers mean. If you’re presenting a complex issue to a group of people, adding another layer of complexity using boxplots does usually not help to make things easier.
Letter-Value Plots (or boxenplots) have been developed to overcome the problem of an inaccurate representation of outliers in boxplots. Let’s have a look at how they work and how we can make use of them in Python using Seaborn.
As the name suggests, letter-value plots are based on so-called letter values. These are recursively defined order statistics with specific depths that can be calculated with the following formula:
Here is an example for a dataset with n=10000 entries like in the tipping dataset used earlier in this article:
If we have a closer look, we can see that d1 corresponds to the median of the dataset, dividing the dataset into two halves. Every further step splits the remaining parts further into two separate regions so that we get the fourths, eights, sixteenths etc.
This recursive division is precisely what’s happening in a boxplot. First, we have the median in the middle, which splits the data points into two halves of 5000 observations each. The remaining data spaces are halved again to retain the quantiles. The boxes around the median then indicate the end of these quantiles (the lowest/highest values for the data points falling in those areas).
In boxenplots, we don’t stop after the quantiles. The remaining data spaces are divided further and more boxes are added to the plot, representing an increasingly smaller space of the dataset:
One could repeat this step indefinitely until the very last data point is reached. But this would make the plot very confusing and we still want to be able to detect outliers using this visualization technique.
Therefore, a stopping criterion is used to determine the last letter-value k for which a box should be visualized. For every letter-value, the trustworthiness is determined by calculating the 95% confidence interval around it. If the interval overlaps with the previous letter-value, the uncertainty for the current letter-value is too high. In this case, the letter-value and the following values are not displayed anymore.
Creating letter-value plots in Seaborn couldn’t be easier if one is already familiar with the boxplot syntax as one can see in the code snippet below:
fig, axs = plt.subplots(nrows=2, ncols=1, figsize=(15,8))

# create grouped boxplot
sns.boxplot(y=bills_df['tip'], x=bills_df['day'], ax=axs[0])
axs[0].set(xlabel='Weekday', ylabel='Tip')

# create grouped boxenplot
sns.boxenplot(y=bills_df['tip'], x=bills_df['day'], ax=axs[1])
axs[1].set(xlabel='Weekday', ylabel='Tip')

We pass the data we’d like to visualize in a list or Series format to Seaborn’s boxenplot() method which renders the graph. The y-parameter allows grouping the data (by a categorical variable) as in the example above.
To discuss the interpretation of a letter-value plot, let’s have a look at the following example:
We can see that the Boxenplot gives us much more information about the tails of the tip’s distribution. In the boxplot below, we can’t tell what the data looks like beyond the 14$ maximum mark:
Are more customers giving 15$ rather than 17$ tip?
The number of outliers around the 18$ mark looks quite similar to the ones around the 21$ mark as well.
And within the whiskers, it’s quite hard to grasp what’s going on as well. There’s a pretty big gap between the 75th percentile at 8.6$ and the maximum at 14$.
The boxenplot, on the other hand, provides more insights in how the data is distributed beyond the quantiles. We can see that the next box ends shortly after the 10$ mark and hence is relatively short, meaning that 50% of customers that are on the right side of the 75th percentile only gave a slightly higher tip. At the same time, the last box beginning approximately at the 19$ mark is quite stretched, indicating that in the higher tipping zone, there’s a higher variance.
Interpreting boxenplots can be more straightforward. The concept of thicker boxes representing a bigger part of the total population is easier to comprehend and facilitates discussions. Hence, letter-value plots can often be a better choice when presenting data to stakeholders.
Boxplots are a popular and easy way to summarize the distribution of a dataset with a handful of key figures. Unfortunately, the linear relationship between sample size and the number of outliers can hide interesting patterns at the tails of the dataset.
Letter-Value plots are a valuable advancement of boxplots that overcome this problem by using recursively defined boxes to visualize the different partitions of a dataset. Since the concept of boxenplots is more intuitive and easier to grasp, this visualization technique can also be a better choice when presenting to stakeholders.
Letter-Value Plots: Boxplots for Large Data by Hofmann et al.
A Complete Guide to Box Plots by Mike Yi
Letter Value Boxplot by Hofmann et al.
Then you might also like one of my other articles: