Skip to content

Can't use labels argument in scale_*() when show.limits = TRUE #5009

Closed
@brunomioto

Description

@brunomioto

It always gives

Error in `check_breaks_labels()`:
! `breaks` and `labels` must have the same length

Reprex

library(tidyverse)

#works
mtcars %>%
  ggplot(aes(hp, mpg, color = mpg)) +
  geom_point() +
  scale_color_stepsn(
    colors = c("#dd3497",
               "#ae017e",
               "#7a0177",
               "#49006a"),
    breaks = c(15,20,25),
    #labels = c("<15","15 text","20 text","25 text",">25")
  )+
  guides(color = guide_colorsteps(show.limits = TRUE))

#doesn't work
mtcars %>%
  ggplot(aes(hp, mpg, color = mpg)) +
  geom_point() +
  scale_color_stepsn(
    colors = c("#dd3497",
               "#ae017e",
               "#7a0177",
               "#49006a"),
    breaks = c(15,20,25),
    labels = c("<15","15 text","20 text","25 text",">25")
  )+
  guides(color = guide_colorsteps(show.limits = TRUE))
#> Error in `check_breaks_labels()`:
#> ! `breaks` and `labels` must have the same length

Created on 2022-10-08 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions