ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Issue warning when geom orientation is ambiguous

Open mine-cetinkaya-rundel opened this issue 5 years ago • 6 comments

I'm using the new-ish bidirectional geom support to make boxplots stretching along the x-axis. If I place a continuous aesthetic on the y axis, I believe the warning should instead say Continuous y aesthetic. Since I'm not sure how ggplot2 could know my intentions (i.e. whether I want x or y to be considered as the grouping variable), maybe it would be less confusing if the warning said something along the lines of "One of x or y aesthetic should be discrete or you can use aes(group = ...) to specify the grouping variable." Not sure if that's too wordy, but something along those lines would be an improvement on the current warning.

library(tidyverse)
ggplot(mpg, aes(y = displ, x = cty)) +
  geom_boxplot()
#> Warning: Continuous x aesthetic -- did you forget aes(group=...)?

Created on 2020-10-28 by the reprex package (v0.3.0)

mine-cetinkaya-rundel avatar Oct 28 '20 10:10 mine-cetinkaya-rundel

I'm not sure I understand exactly what the concern is. The warning seems to follow the orientation of the geom. Do you have a scenario in which the warning is incorrect or confusing?

library(tidyverse)

ggplot(mpg, aes(y = displ, x = cty)) +
  geom_boxplot()
#> Warning: Continuous x aesthetic -- did you forget aes(group=...)?

ggplot(mpg, aes(y = displ, x = cty)) +
  geom_boxplot(orientation = "y")
#> Warning: Continuous y aesthetic -- did you forget aes(group=...)?

Created on 2020-10-28 by the reprex package (v0.3.0)

clauswilke avatar Oct 28 '20 15:10 clauswilke

Alternatively, I could see issuing a warning when the orientation algorithm is encountering an ambiguous scenario and picks the default: "Warning: Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'."

clauswilke avatar Oct 28 '20 15:10 clauswilke

Right, I think a warning that specifies that default orientation is being picked would be equally helpful.

mine-cetinkaya-rundel avatar Oct 28 '20 15:10 mine-cetinkaya-rundel

Ok, I've changed the issue title accordingly.

clauswilke avatar Oct 28 '20 15:10 clauswilke

Is this just the case for geom_boxplot() or are there other examples that are ambiguous as well?

teunbrand avatar Dec 08 '23 08:12 teunbrand

@teunbrand I don't think so.

mine-cetinkaya-rundel avatar Dec 09 '23 18:12 mine-cetinkaya-rundel