Skip to content

guide_colorsteps() from new ggplot2 version #5757

Description

@dominicroye

I found a problem with guide_colorsteps after installing the last ggplot2 version.

I'm not sure why, but the order of classes is not correct. Some of the extreme classes are showing up in the middle. Using the function example data it seems to work, but here it doesn't.

Here is the code to reproduce the bug:

library(terra)
library(giscoR)
library(elevatr)
library(tidyverse)

ger <- gisco_get_countries(country = "Germany")

r <- get_elev_raster(ger, 5) 
r <- rast(r) |> crop(ger) |> mask(ger) 

names(r) <- "elev"

df <- as.data.frame(r, xy = T)

ggplot(df) +
  geom_tile(aes(x, y, 
                fill = cut(elev, c(-50, 0, 25, 50, 100, 250, 500, 1000, 1500, 2000, 2330)))) +
  geom_sf(data = ger, fill = NA) +
  scale_fill_viridis_d() +
  guides(fill = guide_colorsteps()) +
  labs(fill = NULL) +
  theme_void() +
  theme(legend.position = "bottom",
        legend.key.height = unit(.3, "lines"),
        legend.key.width = unit(3, "lines"))

image

Activity

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

    bugan unexpected problem or unintended behaviorguides 📏

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions