Skip to content
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 · 12 comments
Closed

Automatically fill in x for univariate boxplot #2110

hadley opened this issue Apr 17, 2017 · 12 comments

Comments

@hadley
Copy link
Member

@hadley hadley commented Apr 17, 2017

i.e. make this work

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

@foo-bar-baz-qux 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
Copy link

@rpruim 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
Copy link

@dannyparsons 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
Copy link

@ptoche 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
Copy link

@rpruim 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
Copy link

@ptoche 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
Copy link

@rpruim 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
Copy link
Member

@clauswilke 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
Copy link

@ptoche 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
Copy link

@ptoche 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
Copy link

@rpruim rpruim commented Jul 24, 2018

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

@lock
Copy link

@lock lock bot commented Jan 20, 2019

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/

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants