Skip to content

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

Closed

Description

@charliejhadley

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"  

Activity

  1. added
    messages
    on Mar 24, 2021
  2. teunbrand commented on Dec 25, 2022

    @teunbrand
    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"?

  3. added a commit that references this issue on Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    guides 📏messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions