Skip to content

Labelling with scale_fill_stepsn(): “Breaks and labels are different lengths” #4576

@zoeschindler

Description

@zoeschindler

When I use scale_fill_stepsn(), the legend does not show the minimum & maximum value on the legend. When I try to change this by providing a label vector, I get an error “Breaks and labels are different lengths”, although they have the exact same length.
This happend using R version 4.1.0 on Windows 10, using ggplot2 version 3.3.5.
(link to my question on SO)

teunbrand on SO pointed out this issue might be related to the fix of #4423.

This is the plot without changing the labels:

grafik

This is the code for with & without changing the labels, including dummy data:

df_test <- data.frame(long = rep(447030:447050, 21),
                      lat = rep(5379630:5379650, each=21),
                      z = rnorm(21*21))
ggplot(df_test) +
  geom_tile(aes(x=long, y = lat, fill = z)) +
  scale_fill_stepsn(
    limits = c(-3, 3), breaks = seq(-3, 3, 1), labels = seq(-3, 3, 1),
    colors = c("#ff6f69", "grey90", "#00aedb"))

Edit: I just needed to use show.limits = TRUE, but I guess the issue with the label argument remains?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions