Automatically fill in x for univariate boxplot
Closed this issue · 12 comments
i.e. make this work
ggplot(mtcars, aes(y = disp)) + geom_boxplot()Presumably the output would look the same as if x was the same for all y then?
ggplot(mtcars, aes(x = '1', y = disp)) + geom_boxplot()I like the simplified syntax but now the x axis has a numeric scale, which seems unnecessary and potentially confusing. Could there be no labelling as @rpruim suggests? ggplot(mtcars, aes(x = "", y = disp)) + geom_boxplot() almost does this apart from the x label.
ggplot(mtcars, aes(y = disp)) + geom_boxplot()
So we're back to ggplot(mtcars, aes(y = disp, x = factor(""))) + geom_boxplot() + theme(axis.ticks.x = element_blank())
No need for the x aesthetic now (and better to omit it):
library(ggplot2)
ggplot(mtcars, aes(y = disp)) + geom_boxplot() +
theme(axis.ticks.x = element_blank(), axis.text.x = element_blank())Created on 2018-07-24 by the reprex package (v0.2.0).
I suppose it would be nice to avoid the theme stuff -- but how often does one use a single boxplot anyway?
Adding the aesthetic x = factor("") is one way to remove the undesired vertical grid lines which appear in your example.
library(ggplot2)
ggplot(mtcars, aes(y = disp, x = factor(""))) + geom_boxplot()Created on 2018-07-24 by the reprex package (v0.2.0).
I prefer the extra grid lines to "factor("")" and I prefer not specifying an aesthetic that isn't needed. But one way or another there is one more thing to turn off: either vertical grid lines (if you don't want them) or the x label and if the missing x were treated more like a factor, that would save one step.
But low priority (to me) unless it is easy.
The default x value provided by geom_boxplot() is 0. I think it should be factor(0) or factor(""). Boxplots don't normally have a continuous x axis.
@rpruim The vertical grid lines are a consequence of x being treated as numeric. My interpretation of dannyparsons' comment is that a more appropriate default would be to treat x as a factor instead. Oh and as I write this, clauwilke seems to think so too. It should be easy to fix.
If easy to fix, I'm all for it.
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/



