Skip to content

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

Closed
@charliejhadley

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"  

Metadata

Metadata

Assignees

No one assigned

    Labels

    guides 📏messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions