Closed raymondben closed 5 years ago
This is not intended. Thanks for reporting. It seems I'm being foiled by unexpected modify by reference.
All should be good now.
library(ggplot2)
library(ggnewscale)
topography <- expand.grid(x = 1:nrow(volcano), y = 1:ncol(volcano))
topography$z <- c(volcano)
## create two equivalent ggplot objects
p0 <- ggplot(mapping = aes(x, y)) + geom_contour(data = topography, aes(z = z, color = stat(level))) + scale_color_viridis_c(option = "D")
p <- ggplot(mapping = aes(x, y)) + geom_contour(data = topography, aes(z = z, color = stat(level))) + scale_color_viridis_c(option = "D")
p + new_scale_colour()
#> Registered S3 method overwritten by 'ggedit':
#> method from
#> +.gg ggplot2
all.equal(p, p0)
#> [1] TRUE
Created on 2019-07-15 by the reprex package (v0.3.0)
Super! Thanks
Thanks to you for reporting the bug :D
The fix for this bug introduced more serious bugs (see #14), so I'm reverting the fix and looking for other options. Sorry, @raymondben!
Now it's got to be fixed.
Heheh. If a job's worth doing, it's worth doing twice, yeah? Thanks again.
This might be intended behaviour, in which case just close the issue - but it caught me out! I didn't find it mentioned in the docs, but maybe I missed it? Adding
new_scale
to a ggplot object modifies that object. In some cases this caused errors for me in later code, because the ggplot object has changed unexpectedly.Should
p + new_scale()
change thep
object, if it isn't being assigned back top
?