Why are my ggplot2 boxplot whiskers invisible while dots remain?

Can a ggplot2 boxplot have zero-length whiskers?

In ggplot2, a whisker has zero length when its endpoint equals Q1 or Q3; the default fence is 1.5 × IQR from each quartile.

On this page

Published and tested 20 November 2026.

Values outside those fences are drawn as outlier symbols. When outliers are present, the endpoint calculation includes Q1 and Q3 along with the observations inside the fences, so an endpoint can coincide with its box edge. This example uses finite, unweighted values, no axis transformation, and the defaults coef = 1.5 and quantile.type = 7. The versioned calculation source shows the rule.

Which values make the whiskers collapse?

A contains 1, 2, 2, 2, 20; B contains 1, 2, 3, 4, 5, 6, 7, 8, 20. In A, Q1, the median and Q3 all equal 2. IQR is 0, both fences equal 2, and both whiskers end at 2. Values 1 and 20 appear as separate dots. In B, IQR is 4, the fences are −3 and 13, and the whiskers end at observed values 1 and 8. The value 20 is outside the upper fence.

This article uses simulated example data.

Group n Q1 Median Q3 Lower whisker Upper whisker Outlier values
A 5 2 2 2 2 2 1, 20
B 9 3 5 7 1 8 20

The example uses the type 7 quantiles used by this unweighted ggplot2 calculation. Inspect the calculated endpoints to see whether a whisker collapses.

How can I show the observations without changing the whiskers?

Add a point layer with horizontal jitter and height = 0, and use outlier.shape = NA in the boxplot layer to avoid drawing the outlier dots twice.

I start with group B and trace the upper whisker back to an observation. It stops at 8. The cutoff helps choose that observation, but drawing the whisker all the way to the cutoff would give a different figure.

Before: A is a line at 2 with dots at 1 and 20; B has a box from 3 to 7, whiskers at 1 and 8, and a dot at 20.
Open full-size image
Before: the default boxplot. A has zero box height and zero whisker lengths; B has visible whiskers. Orange dots are the boxplot's outlier symbols.
After: all five observations in A and all nine in B are overlaid in teal; the original box and whisker positions remain.
Open full-size image
After: all 14 observations appear as teal dots. A's three values at 2 are separated horizontally. The boxplot summaries and every observation's y value are unchanged. On a narrow screen, scroll inside each figure.

Does hiding outlier symbols change the data range?

outlier.shape = NA keeps the full range available to the axes. outliers = FALSE discards the outlier output from the boxplot layer, allowing its automatic scale to shrink; it leaves the source data frame intact. The official reference distinguishes these options.

In the script's boxplot-only checks, default and hidden-symbol layers both train the y scale on 1 to 20. The discarded-outlier layer trains it on 1 to 8. The final raw-point overlay retains 1 to 20. These ranges come from scale training before visual expansion. Hiding symbols or adding raw points leaves A's whisker endpoints at 2.

How do I reproduce and inspect the result?

With ggplot2 installed, run Rscript --vanilla example.R in an output folder. Tested with R 4.5.3 and ggplot2 4.0.4. Inspect ggplot_build(before)$data[[1]] for ymin, lower, middle, upper, ymax and outliers; the script compares them with the numbers above.

These are the code, data and result files used in this article. Choose a file below to run the example or compare your results.

  • example.RComplete example code to run on your computer.
  • synthetic.csvThe input data used in the example; open it as a table.
  • boxplot-summary.csvThe calculated boxplot statistics.
  • range-check.csvData ranges and boxplot whisker endpoints to compare.
  • before.pngThe figure before the change, for comparison.
  • after.pngThe figure after applying the settings in this article.
  • after.pdfThe result in PDF format, for viewing and page layout.

The PNG files are 1200 × 900 pixels at approximately 300 PPI; the PDF page is 101.6 × 76.2 mm. Original example code, data, figures and prose are CC0-1.0. For a mean ± sample SD overlay, use the separate group-summary answer.

# Original example: CC0-1.0.
library(ggplot2)
d <- data.frame(group = factor(c(rep("A", 5), rep("B", 9)), levels = c("A", "B")),
                value = c(1, 2, 2, 2, 20, 1, 2, 3, 4, 5, 6, 7, 8, 20))
base <- ggplot(d, aes(group, value)) +
  scale_x_discrete(labels = c(A = "A (n = 5)", B = "B (n = 9)")) +
  scale_y_continuous(breaks = seq(0, 20, 5)) +
  labs(x = "Group", y = "Response (arbitrary units)") +
  theme_classic(base_size = 11) +
  theme(plot.caption = element_text(size = 8), plot.margin = margin(8, 8, 8, 8))
before <- base + geom_boxplot(width = .45, fill = "white", outlier.colour = "#D55E00") +
  labs(caption = "Default boxplot: whiskers use 1.5 IQR")
hidden <- base + geom_boxplot(width = .45, fill = "white", outlier.shape = NA)
after <- hidden +
  geom_point(position = position_jitter(width = .12, height = 0, seed = 15),
             size = 2, colour = "#17665c") +
  labs(caption = "Boxplot + every observation; horizontal jitter only")
discarded <- base + geom_boxplot(outliers = FALSE)
b <- ggplot_build(before)
a <- ggplot_build(after)
cols <- c("ymin", "lower", "middle", "upper", "ymax")
expected <- data.frame(ymin = c(2, 1), lower = c(2, 3), middle = c(2, 5),
                       upper = c(2, 7), ymax = c(2, 8))
stopifnot(isTRUE(all.equal(b$data[[1]][cols], expected, check.attributes = FALSE)),
          identical(b$data[[1]][cols], a$data[[1]][cols]),
          identical(b$data[[1]]$outliers, list(c(1, 20), 20)),
          nrow(a$data[[2]]) == nrow(d), identical(a$data[[2]]$y, d$value))
summary <- data.frame(group = levels(d$group), n = c(5, 9), expected,
                      IQR = c(0, 4), lower_fence = c(2, -3), upper_fence = c(2, 13),
                      lower_whisker_length = c(0, 2), upper_whisker_length = c(0, 1),
                      outlier_values = c("1;20", "20"))
yrange <- function(plot) ggplot_build(plot)$layout$panel_scales_y[[1]]$range$range
ranges <- rbind(default = yrange(before), hidden = yrange(hidden),
                 discarded = yrange(discarded), raw_overlay = yrange(after))
colnames(ranges) <- c("minimum", "maximum")
stopifnot(identical(unname(ranges["default", ]), c(1, 20)),
          identical(unname(ranges["hidden", ]), c(1, 20)),
          identical(unname(ranges["discarded", ]), c(1, 8)),
          identical(unname(ranges["raw_overlay", ]), c(1, 20)))
ggsave("before.png", before, width = 1200, height = 900, units = "px", dpi = 300, bg = "white")
ggsave("after.png", after, width = 1200, height = 900, units = "px", dpi = 300, bg = "white")
ggsave("after.pdf", after, width = 101.6, height = 76.2, units = "mm", bg = "white")
write.csv(d, "synthetic.csv", row.names = FALSE)
write.csv(summary, "boxplot-summary.csv", row.names = FALSE)
write.csv(data.frame(option = rownames(ranges), ranges), "range-check.csv", row.names = FALSE)
capture.output(sessionInfo(), file = "session-info.txt")
print(summary)
print(ranges)
cat("PASS:14 values; A has zero-length whiskers; B ends at1/8; summaries unchanged; all raw y preserved; hide/discard ranges checked.\n")

Where can I verify the method and reuse the example?

The original example is CC0-1.0. R retains GPL-2 or GPL-3 and ggplot2 its MIT license; install the required packages separately to run the code. CC0-1.0