Skip to content

geom_boxplot Whiskers never appear when IQR = 0 (upper - lower = 0) #5511

@math-mcshane

Description

@math-mcshane

I found a problem with ...

geom_boxplot

I expected ...

Whiskers to appear. There's no convenient way to get whiskers to appear when IQR = 0 (upper - lower = 0) (that I am aware of*). Setting coef = 1000 or some other large value doesn't work (as it would in most other cases; it wouldn't be reasonable to expect coef*0 to be anything other than 0). In particular, it would make sense to let the whiskers extend to the min and max of the data (See the first bullet: https://en.wikipedia.org/wiki/Box_plot#Whiskers -- allowing boxplot whiskers to extend to the min and max should be a reasonable option). I debated whether to submit as bug or feature request, but since I'm discussing an edge case where IQR = 0 (rare), this seemed more like a bug.

Here is the code to reproduce the bug:

y = data.frame(x = c(0, 10, 10, 10, 100))

# Produces a boxplot with "box" of width 0 (IQR = 0)
ggplot(data = y, aes(x = x)) + geom_boxplot()
# No matter what we change coef to, we will never get whiskers
ggplot(data = y, aes(x = x)) + geom_boxplot(coef = 1000)
# Want: boxplot that looks like this: -|-

# Can hack this slightly with: 
ggplot(data = y, aes(x = x)) + geom_boxplot(xmin = min(y$x), xmax = max(y$x))
# And make the outliers disappear:
ggplot(data = y, aes(x = x)) + geom_boxplot(xmin = min(y$x), xmax = max(y$x), outlier.alpha = 0)

*Apologies if there is already a parameter that can be set to allow this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions