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

Add error to direction argument of guide_*() #4364

Closed
charliejhadley opened this issue Mar 3, 2021 · 1 comment · Fixed by #4879
Closed

Add error to direction argument of guide_*() #4364

charliejhadley opened this issue Mar 3, 2021 · 1 comment · Fixed by #4879
Labels
guides 📏 messages requests for improvements to error, warning, or feedback messages

Comments

@charliejhadley
Copy link

The direction argument of guide_*() functions can only be "horizontal" or "vertical". At present an unhelpful error message is returned in case of error:

library("ggplot2")

ggplot(quakes,
       aes(x = long,
           y = lat,
           colour = mag)) +
  geom_point() +
  guides(colour = guide_colorbar(direction = "horiz"))
#> Error in if (!g$title.position %in% c("top", "bottom", "left", "right")) {: argument is of length zero

In line with the tidyverse style guide an error like this would be more suitable:

library("ggplot2")

ggplot(quakes,
       aes(x = long,
           y = lat,
           colour = mag)) +
  geom_point() +
  guides(colour = guide_colorbar(direction = "horiz"))
#> Error: The direction argument of guide_colorbar() must be either "vertical" or "horizontal"  
@thomasp85 thomasp85 added guides 📏 messages requests for improvements to error, warning, or feedback messages labels Mar 24, 2021
@teunbrand
Copy link
Collaborator

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

Error in guide_colorbar():
! direction must be one of "horizontal" or
"vertical", not "horiz".
ℹ Did you mean "horizontal"?

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
guides 📏 messages requests for improvements to error, warning, or feedback messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants