In this post we will take a closer look at the boxplot, a ubiquitous tool for data visualization (e.g., Tukey, 1977). The data set that we will use to highlight the key concepts is relatively small:

So the data set contains, for each of the eight planets in our solar system, the distance to the sun in astronomical units (AU), where AU=1 is the average distance from the earth to the sun. A boxplot essentially divides these data into four equal-sized groups or quarters. We personally believe that classic boxplots can be usefully augmented by modern data visualization tools, but we will revisit this issue in a later post where we will discuss the so-called raincloud plot. Nevertheless, the classic boxplot remains an essential component of exploratory data analysis.
First, a Table with Ingredients
After entering the data in JASP, we navigate to Descriptives -> Descriptive Statistics -> Statistics, and tick a number of boxes so as to produce the table below:

This descriptive table contains the most important ingredients for the boxplot:
[1] The median, that is, the value that splits the data into two equal halves, such that 50% of the observations have values lower than the median and 50% have values higher than the median. The ordered AU values for the eight planets are 0.4, 0.7, 1.0, 1.5, 5.2, 9.6, 19.2, 30. Because we have an even number of planets, there is not one single specific value that divides the data into two equal halves; consequently, the median is defined as the average of the two middle values, that is (1.5 + 5.2)/2 = 3.35. The median is also known as the second quartile or Q2.
[2] The 25th percentile, that is, the value that divides the data such that 25% of the observations have values lower than the 25th percentile. This is also called the “lower quartile” or the first quartile (Q1), and it is the median of the lowest half of the data. From the table below you see that Q1 = 0.925.
[3] The 75th percentile, that is, the value that divides the data such that 75% of the observations have values lower than the 75th percentile. This is also called the “upper quartile” or the third quartile (Q3) and it is the median of the upper half of the data. From the table below you see that Q3 = 12.000.
[4] The interquartile range, that is, the range that contains the middle 50% of the data. It is defined as Q3-Q1, so here it equals 12.000 – 0.925 = 11.075.
Note that the three quartiles Q1, Q2, Q3 divide the data into four equal sized parts (“quarters”).As an aside, the computation of the quantiles (the generic name for cut points in a distribution) is not trivial. There exists at least nine different methods to compute quantiles (e.g., Hyndman & Fan, 1996), and what is used as the default method differs between the major statistical packages. JASP uses the default in R, which is “type = 7”. In the future JASP will allow users a choice between quantile methods; for now, we have to use the R default. So you may look at the AU data and think “Surely Q1 should be 0.7, because 0.4 and 0.7 are the lowest 25% of the data; I don’t understand why JASP returns 0.925”. In R, “type = 1”, “type = 3”, and “type = 4” all return Q1 = 0.7. But the R default is “type = 7” (which is actually more fancy than the other types), which returns 0.925. Luckily, the differences between the method quickly become smaller as the data set grows.
Next, the Boxplot
With these ingredients in place, we now turn to the boxplot, which we obtain by navigating to “Customizable Plots” and ticking “Boxplots” (and unticking the additional display options except for the color palette and “Label outliers”):

Inside the green box there is a thick horizontal line: this is the median. The box extends from Q1 to Q3, the IQR. This leaves a discussion of the whiskers — the vertical lines that emanate upward and downward of the box. To draw the upper whisker, we first compute UpperRange = Q3 + 1.5*IQR = 12.000 + 1.5*11.075 = 28.6125. The upper whisker will extent to the largest data point that falls inside this UpperRange. In our dataset, Uranus has AU = 19.2 and Neptune has AU = 30, so the upper whisker extends from Q3 to 19.2. Similarly, to draw the lower whisker, we first compute LowerRange = Q1 – 1.5*IQR = 0.925 – 1.5*11.075 = -15.6875. The lower whisker will extent to the lowest data point that falls inside this LowerRange. In our dataset, the lowest value is for Mercury, which has AU = 0.4, so the lower whisker extends to 0.4. This explains why the upper and lower whiskers are not equally long. Both are based on a computation extending the respective quartiles by 1.5 IQR, but each extends up to the most extreme observation that still falls in this range. This is highly desirable, since it ensures that the whisker covers values that are actually possible — note that (Q1 – 1.5*IQR) = -15.6875, and that negative values for AU are impossible. We would not want to draw a whisker in a region of impossible values.
All observed values that fall outside the whiskers are plotted as small dots; here we see that the value of 30, the AU of Neptune, is a “boxplot outlier” as its value is larger than 28.6125.
To be continued…
References
Hyndman, R. J., & Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50, 361-365.
Tukey, J. W. (1977). Exploratory data analysis. Reading, MA: Addison-Wesley.
Authors
Eric-Jan Wagenmakers (CEO) and the JASP Services BV Team



