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

Confusing error when theme(legend.direction = .) incorrectly entered #4930

Closed
ngreifer opened this issue Aug 4, 2022 · 2 comments · Fixed by #4879
Closed

Confusing error when theme(legend.direction = .) incorrectly entered #4930

ngreifer opened this issue Aug 4, 2022 · 2 comments · Fixed by #4879
Labels
messages requests for improvements to error, warning, or feedback messages

Comments

@ngreifer
Copy link

ngreifer commented Aug 4, 2022

When running ggplot() with a legend and using theme(legend.position = .) to change the legend direction, an invalid argument causes an unclear error. I also feel like abbreviations should be allowed for this argument since it only accepts two strings.

library(ggplot2)
ggplot(mpg, aes(x = cty, fill = drv)) +
  geom_histogram() +
  theme(legend.direction = "v")

## Error in if (!g$title.position %in% c("top", "bottom", "left", "right")) { : 
##  argument is of length zero
@teunbrand
Copy link
Collaborator

Thanks, that is indeed an inelegant error message. After #4879 gets merged, this will return the following error message:

Error:
! direction must be one of "horizontal" or "vertical", not "v".
ℹ Did you mean "vertical"?

Quoting from the tidyverse style guide:

I generally believe that partial matching is a bad idea, because it makes code harder to read.

So I don't think there is a good chance that ggplot2 will allow this as a partially matched argument.

@teunbrand teunbrand added the messages requests for improvements to error, warning, or feedback messages label Dec 23, 2022
@teunbrand
Copy link
Collaborator

I just realised that this is a duplicate of #4364, so I'll close this issue in favour of the other one.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Dec 25, 2022
teunbrand added a commit that referenced this issue Apr 24, 2023
The guide system, as the last remaining chunk of ggplot2, has been rewritten 
in ggproto. The axes and legends now inherit from a <Guide> class, which makes
them extensible in the same manner as geoms, stats, facets and coords 
(#3329, @teunbrand). In addition, the following changes were made:
    * Styling theme parts of the guide now inherit from the plot's theme 
      (#2728). 
    * Styling non-theme parts of the guides accept <element> objects, so that
      the following is possible: `guide_colourbar(frame = element_rect(...))`.
    * Primary axis titles are now placed at the primary guide, so that
      `guides(x = guide_axis(position = "top"))` will display the title at the
      top by default (#4650).
    * Unknown secondary axis guide positions are now inferred as the opposite 
      of the primary axis guide when the latter has a known `position` (#4650).
    * `guide_colourbar()`, `guide_coloursteps()` and `guide_bins()` gain a
      `ticks.length` argument.
    * In `guide_bins()`, the title no longer arbitrarily becomes offset from
      the guide when it has long labels.
    * The `order` argument of guides now strictly needs to be a length-1 
      integer (#4958).
    * More informative error for mismatched 
     `direction`/`theme(legend.direction = ...)` arguments (#4364, #4930).
    * `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
messages requests for improvements to error, warning, or feedback messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants