Skip to content

guide_colorsteps() doesn't work as expected #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pascaloettli opened this issue Mar 19, 2024 · 4 comments
Closed

guide_colorsteps() doesn't work as expected #188

pascaloettli opened this issue Mar 19, 2024 · 4 comments

Comments

@pascaloettli
Copy link

Trying to reproduce the example of discretised_scale(), it fails to produce the correct result:

library(metR)
library(ggplot2)
library(data.table)
temperature <- copy(temperature)
temperature[, air.z := Anomaly(air), by = .(lat, lev)]

ggplot(temperature[lev == 300], aes(lon, lat, z = air.z)) +
  geom_contour_fill(aes(fill = after_stat(level)), breaks = c(-10, -8, -6, -2, -1, 0, 6, 8, 10)) +
  guides(fill = guide_colorsteps())

Rplot12

ggplot2_3.5.0
metR_0.15.0

@pascaloettli
Copy link
Author

ggplot2 3.5.0 breaks the function. It works as expected with ggplot2 3.4.4

Rplot13

@eliocamp
Copy link
Owner

guide_colorsteps() is a ggplot2 function. The changes in the guide system seem to have messed it up somehow. Here's an pure ggplot2 example:

library(ggplot2)
levels <- pretty(range(volcano))

volcano2 <- reshape2::melt(volcano) |> 
  transform(value_discrete = cut(value, 
                                 breaks = levels,
                                 ordered_result = TRUE))

ggplot(volcano2, aes(Var1, Var2)) +
  geom_raster(aes(fill = value_discrete)) 

ggplot(volcano2,  aes(Var1, Var2)) +
  geom_raster(aes(fill = value_discrete)) +
  guides(fill = guide_colorsteps())

Created on 2024-03-20 with reprex v2.0.2

I opened an issue on their repo, which you can follow here: tidyverse/ggplot2#5786

@eliocamp
Copy link
Owner

BTW, this has been fixed in the development version of ggplot2

@pascaloettli
Copy link
Author

Sorry, I missed the fact is was a ggplot2 function and not a metR function. Sorry for the annoyance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants