Skip to content
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

ggnewscale doesn't work with scale_continuous or scale_discrete families #2

Closed
willgearty opened this issue Jan 23, 2019 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@willgearty
Copy link

The example in the readme works fine for me, but as soon as I introduce any function of the scale_continuous family or scale_discrete family like this:

library(ggplot2)
library(ggnewscale)
# Equivalent to melt(volcano)
topography <- expand.grid(x = 1:nrow(volcano),
                          y = 1:ncol(volcano))
topography$z <- c(volcano)

# point measurements of something at a few locations
set.seed(42)
measurements <- data.frame(x = runif(30, 1, 80),
                           y = runif(30, 1, 60),
                           thing = rnorm(30))

ggplot(mapping = aes(x, y)) +
  geom_contour(data = topography, aes(z = z, color = stat(level))) +
  scale_x_continuous(limits = c(25, 75)) +
  # Color scale for topography
  scale_color_viridis_c(option = "D") +
  # geoms below will use another color scale
  new_scale_color() +
  geom_point(data = measurements, size = 3, aes(color = thing)) +
  # Color scale applied to geoms added after new_scale_color()
  scale_color_viridis_c(option = "A")

it breaks and gives the following error:
Error in get(as.character(FUN), mode = "function", envir = envir) : object 'guide_none' of mode 'function' was not found

Based on the error, I believe I've tracked down the problem to this line of code. After messing around with some ggplot objects, it looks like these particular scales don't have guides, so the names of the guides are "none", which is still a character, so it proceeds but doesn't find any function guide_none().

I think all you would need to do is change the if statement here to
if (is.character(scale$guide) & !(scale$guide == "none")) { but I'm actually not sure if this would break anything else. If I get a chance, I'll fork and try it out.

@eliocamp eliocamp added the bug Something isn't working label Jan 23, 2019
@eliocamp
Copy link
Owner

Thanks for the detailed bug report!

It seems that the problem is that new_scale() is changing the x scale when it's not supposed to. Putting scale_x_continuous(limits = c(25, 75)) after new_scale() is a workaround.

It's fixed in the new commit!

@willgearty
Copy link
Author

Fantastic, thank you! Now implemented in https://github.com/willgearty/deeptime!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants