Skip to content

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

Closed

Description

@ngreifer

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

Activity

  1. teunbrand commented on Dec 23, 2022

    @teunbrand
    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.

  2. added
    messages
    on Dec 23, 2022
  3. teunbrand commented on Dec 25, 2022

    @teunbrand
    Collaborator

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

  4. 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

    messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions