Closed alhenry closed 8 months ago
This is supposed to be fixed by #57, which is included in the latest release. All tests pass with the current ggplot2 version. Make sure you're running the latest ggnewscale version. If the problem persists, please submit a reproducible example so I can investigate further.
I've tested with the latest version of ggplot2 and ggnewscale on CRAN and no longer found the issue. Will close this for now. Sorry for the false alarm!
Good to know! Do report any other issue, though.
_Edit: I wrote all of this and then realized the ggplot 3.5 now allows for guide = "colorsteps"
, not just guide = guide_colorsteps()
. With the former, I get the desired behavior. Editing, rather than deleting, this comment for anyone who may find this helpful._
I continue to have the same error, when I set guide = guide_colorsteps()
.
Here's a reproducible example:
ggplot(mpg) +
geom_point(aes(x = cty, y = hwy, color = displ)) +
scale_color_stepsn(
colors = c("yellow", "red"),
guide = guide_colorsteps()) +
ggnewscale::new_scale_color()
# Error in scale$guide == "none" :
# comparison (==) is possible only for atomic and list types
I don't get the error if I don't include guide = guide_colorsteps()
[^1], nor if `guide = "legend". Both of the following work:
[^1]: Normally, one wouldn't include guide = guide_colorsteps()
in scale_color_stepsn
, as it is the default behavior; however, in my non-reprex usage I sometimes set guide = "legend"
: guide = if (diff(lengths(list(params$labels, params$breaks))) == 1) "legend" else guide_colorsteps()
ggplot(mpg) +
geom_point(aes(x = cty, y = hwy, color = displ)) +
scale_color_stepsn(colors = c("yellow", "red")) +
ggnewscale::new_scale_color()
ggplot(mpg) +
geom_point(aes(x = cty, y = hwy, color = displ)) +
scale_color_stepsn(
colors = c("yellow", "red"),
guide = "legend") +
ggnewscale::new_scale_color()
If, rather than setting the guide in scale_color_stepsn
but in guides()
, there is no error with ggnewscale::new_scale_color()
, but the guide setting persists after ggnewscale::new_scale_color()
, and that causes a different error when the guide type is different in the next plot:
ggplot(mpg) +
geom_point(aes(x = cty, y = hwy, color = displ)) +
scale_color_stepsn(colors = c("yellow", "red")) +
guides(color = guide_colorsteps()) +
ggnewscale::new_scale_color() +
# Shifting x and y so they are obviously separate from previous layer
geom_point(aes(x = cty + 10, y = 50 - hwy, color = class), shape = 1)
# Error in `parse_binned_breaks()`:
# ! Breaks are not formatted correctly for a bin legend.
# ℹ Use `(<lower>, <upper>]` format to indicate bins.
# Run `rlang::last_trace()` to see where the error occurred.
# Warning message:
# In parse_binned_breaks(scale, breaks) : NAs introduced by coercion
The function
new_scale_*()
throws the following error in ggplot2 3.5.0:Presumably this is something related to the new behaviour of guides & scales in ggplot?