New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically fill in x for univariate boxplot #2110

Closed
hadley opened this Issue Apr 17, 2017 · 11 comments

Comments

Projects
None yet
7 participants
@hadley
Member

hadley commented Apr 17, 2017

i.e. make this work

ggplot(mtcars, aes(y = disp)) + geom_boxplot()
@foo-bar-baz-qux

This comment has been minimized.

Contributor

foo-bar-baz-qux commented Jul 9, 2017

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()
@rpruim

This comment has been minimized.

rpruim commented Nov 15, 2017

Ideally, the output should not be exactly like this:

library(ggplot2)
ggplot(mtcars, aes(x = "1", y = disp)) + geom_boxplot()

There is no reason for the labeling of the x-axis in such a plot (neither the x nor the 1 should be there.)

@dannyparsons

This comment has been minimized.

dannyparsons commented Jul 23, 2018

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()

image

@ptoche

This comment has been minimized.

ptoche commented Jul 24, 2018

So we're back to ggplot(mtcars, aes(y = disp, x = factor(""))) + geom_boxplot() + theme(axis.ticks.x = element_blank())

@rpruim

This comment has been minimized.

rpruim commented Jul 24, 2018

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?

@ptoche

This comment has been minimized.

ptoche commented Jul 24, 2018

@rpruim

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).

@rpruim

This comment has been minimized.

rpruim commented Jul 24, 2018

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.

@clauswilke

This comment has been minimized.

Member

clauswilke commented Jul 24, 2018

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.

@ptoche

This comment has been minimized.

ptoche commented Jul 24, 2018

@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.

@ptoche

This comment has been minimized.

ptoche commented Jul 24, 2018

Possibly this commit: 42c86d5

and these lines:

data$x <- data$x %||% 0

params$width <- params$width %||% (resolution(data$x %||% 0) * 0.75)

@rpruim

This comment has been minimized.

rpruim commented Jul 24, 2018

If easy to fix, I'm all for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment