Sub topic 10
Drawing a Boxplot from Data
This chapter turns a raw list of numbers into a boxplot. It assumes you can already find the median, the quartiles (Q1, Q2, Q3), and the interquartile range (IQR). It also assumes you can place values on a labeled number line. If any of those feel shaky, review the earlier chapters first. Drawing a boxplot is mostly bookkeeping: you compute five numbers, optionally test for outliers, and place marks on a scale.
On the GRE you will rarely draw a boxplot. You will usually read one, or choose which of several boxplots matches a data set. Drawing one yourself is still the fastest way to learn what each part of the picture means.
What the Picture Is Made Of
A boxplot has four visual parts. Each one comes from a number you already know how to compute.
| Part | Drawn at | Meaning |
|---|---|---|
| Box | From Q1 to Q3 | The middle half of the data. Its length is the IQR. |
| Line inside the box | At the median (Q2) | The middle value of the whole set. |
| Whiskers | From the box out to the smallest and largest values | The spread of the remaining data. |
| Separate dots | Beyond the whiskers | Outliers, if the problem uses the 1.5 x IQR rule. |
The box and the median line are the same in every convention. The whiskers are where conventions differ, and that is the main source of confusion.
The Procedure
- Sort the data from least to greatest.
- Find the median of the whole list. This is Q2.
- Split the list into a lower half and an upper half. If the count is odd, leave the middle value out of both halves.
- Find the median of the lower half (Q1) and of the upper half (Q3).
- Record the minimum and maximum.
- Choose a number-line scale that covers the minimum to the maximum, with evenly spaced tick marks.
- Draw the box from Q1 to Q3, then the median line, then the whiskers.
If the problem mentions outliers, add a check between steps 5 and 6. Compute the fences Q1 - 1.5 x IQR and Q3 + 1.5 x IQR. Any value outside them is drawn as a separate point. The whisker then stops at the most extreme value that is still inside the fences.
Worked Example 1: Odd Number of Values
Use the data set from the earlier chapters: 3, 5, 7, 8, 12, 13, 14, 18, 21. It is already sorted and has 9 values.
- The median is the 5th value, 12.
- Leave 12 out. The lower half is 3, 5, 7, 8, and its median is (5 + 7) / 2 = 6. So Q1 = 6.
- The upper half is 13, 14, 18, 21, and its median is (14 + 18) / 2 = 16. So Q3 = 16.
- The minimum is 3 and the maximum is 21.
- IQR = 16 - 6 = 10.
Now check for outliers. The fences are 6 - 15 = -9 and 16 + 15 = 31. Every value lies between them, so there are no outliers and the whiskers run to 3 and 21.
On the number line, the box spans 6 to 16 with a line at 12. The left whisker is 3 units long, from 3 to 6. The right whisker is 5 units long, from 16 to 21. The median sits closer to Q3 than to Q1, because 12 - 6 = 6 and 16 - 12 = 4. That tells you the lower part of the middle half is stretched out more than the upper part.
Worked Example 2: Even Count with an Outlier
Take 12 values: 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 45.
- With an even count, the median is the average of the 6th and 7th values: (12 + 13) / 2 = 12.5.
- The lower half is the first six values, 4 through 12. Its median is (7 + 9) / 2 = 8. So Q1 = 8.
- The upper half is the last six values, 13 through 45. Its median is (16 + 18) / 2 = 17. So Q3 = 17.
- IQR = 17 - 8 = 9.
- The fences are 8 - 13.5 = -5.5 and 17 + 13.5 = 30.5.
The value 45 is above 30.5, so it is an outlier. It is drawn as a separate dot. The upper whisker stops at 19, the largest value inside the fence. The lower whisker reaches 4, because 4 is inside the lower fence.
The maximum of the data set is 45, but the whisker does not reach it. This is why "the right end of the plot" is not always the maximum.
Checking Your Work with Code
The function below computes every drawing coordinate. It uses the same halving method as the earlier chapters.
def median(values):
n = len(values)
mid = n // 2
if n % 2 == 1:
return values[mid]
return (values[mid - 1] + values[mid]) / 2
def boxplot_parts(data):
s = sorted(data)
half = len(s) // 2
lower = s[:half]
upper = s[half + len(s) % 2:] # skip the middle value when n is odd
q1, q2, q3 = median(lower), median(s), median(upper)
iqr = q3 - q1
low_fence = q1 - 1.5 * iqr
high_fence = q3 + 1.5 * iqr
inside = [v for v in s if low_fence <= v <= high_fence]
outliers = [v for v in s if v < low_fence or v > high_fence]
return {
"q1": q1,
"median": q2,
"q3": q3,
"iqr": iqr,
"fences": (low_fence, high_fence),
"whiskers": (min(inside), max(inside)),
"outliers": outliers,
}
for data in ([3, 5, 7, 8, 12, 13, 14, 18, 21],
[4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 45]):
parts = boxplot_parts(data)
for key, value in parts.items():
print(key, value)
print()For the first data set, the output shows Q1 = 6.0, median = 12, Q3 = 16.0, IQR = 10.0, whiskers (3, 21), and no outliers. For the second, it shows Q1 = 8.0, median = 12.5, Q3 = 17.0, IQR = 9.0, fences (-5.5, 30.5), whiskers (4, 19), and outliers [45].
The code treats a value exactly equal to a fence as inside. That matches the usual wording, where an outlier is a value beyond the fence.
Edge Cases
- Repeated values. Duplicates are kept. If Q1 equals the minimum, the lower whisker has zero length and the box starts at the end of the plot. The same is true at the top.
- No outliers on one side. The whisker on that side runs to the minimum or maximum as usual. Outliers can appear on both sides, on one side, or on neither.
- Several outliers. Each one gets its own dot. The whisker still stops at the most extreme value inside the fence.
- Very small sets. With 4 values, each half has 2 values. With 2 values, each half has 1 value, so Q1 and Q3 are the two data values themselves. The method still works, but the plot says little.
- Different software. Spreadsheets and statistics packages may use other quartile formulas and give slightly different Q1 and Q3 for the same list. GRE questions that ask for quartiles use data sets where the halving method is clear, or they give the values directly.
Scale and Proportion
A boxplot is drawn on a number line, so distances must match values. Equal-looking pieces of the plot are not equal in value unless the numbers say so.
- The box length is the IQR, and the whisker lengths are the gaps from the box to the extreme values.
- Each of the four sections (minimum to Q1, Q1 to median, median to Q3, Q3 to maximum) holds about one quarter of the data, no matter how long it looks.
- A long section means the values there are spread out. A short section means they are packed together.
For example, if a boxplot represents 40 values, then about 10 values lie in each section. About 20 lie inside the box. The median is the 20th and 21st values averaged, and this holds even if the right half of the box is twice as long as the left half.
Common Errors
| Error | Why it is wrong | Fix |
|---|---|---|
| Putting the median in both halves when n is odd | It changes Q1 and Q3 | Leave the middle value out of both halves |
| Drawing whiskers to the fences | Fences are cutoffs, not data | End each whisker at a real value |
| Using the mean for the line in the box | The line is the median | Use Q2 |
| Making the box four equal-looking parts | Sections have equal counts, not equal lengths | Use the actual values and scale |
| Forgetting to sort first | Halves of an unsorted list are meaningless | Sort before any split |
| Using uneven tick spacing | Distorts every comparison | Place ticks at equal intervals |
Exercise
Draw the boxplot parts for 10, 12, 15, 15, 18, 20, 22, 25, 40. Give Q1, the median, Q3, the IQR, the fences, where each whisker ends, and any outliers.
Show answer
There are 9 values. The median is the 5th value, 18. The lower half is 10, 12, 15, 15, so Q1 = (12 + 15) / 2 = 13.5. The upper half is 20, 22, 25, 40, so Q3 = (22 + 25) / 2 = 23.5. IQR = 23.5 - 13.5 = 10. The fences are 13.5 - 15 = -1.5 and 23.5 + 15 = 38.5. The value 40 is above 38.5, so it is an outlier drawn as a dot. The upper whisker ends at 25, and the lower whisker ends at 10.
Exercise
A data set is 1, 3, 4, 6, 7, 9, 12, 20. Using the 1.5 x IQR rule, is 20 an outlier?
Show answer
With 8 values, the lower half is 1, 3, 4, 6 and Q1 = (3 + 4) / 2 = 3.5. The upper half is 7, 9, 12, 20 and Q3 = (9 + 12) / 2 = 10.5. IQR = 7, so the upper fence is 10.5 + 10.5 = 21. Since 20 is less than 21, it is not an outlier, and the upper whisker ends at 20.
Exercise
A boxplot summarizes 60 test scores. The part of the box from the median to Q3 is drawn three times as long as the part from Q1 to the median. About how many scores lie in each of those two parts, and what does the difference in length tell you?
Show answer
About 15 scores lie in each part, because each quarter of the data holds the same count. The longer part means the scores between the median and Q3 are more spread out than those between Q1 and the median.