eliocamp / ggnewscale

Multiple Fill, Color and Other Scales in `ggplot2`
https://eliocamp.github.io/ggnewscale/
GNU General Public License v3.0
406 stars 18 forks source link

ggnewscale only works with ggmap when extent = "normal" #3

Closed tomasleon closed 5 years ago

tomasleon commented 5 years ago

I've been experimenting with ggnewscale and ggmap, and it seems to work provided you define extent = "normal". If you don't set the extent, it will default to extent = "panel", which causes it to fail with Error in get(as.character(FUN), mode = "function", envir = envir) : object 'guide_none' of mode 'function' was not found like in Issue #2. The same happens when extent = "device". See below; NB for ggmap you now need an API key to retrieve maps. Not sure why this happens but thought I would mention it in case someone else had insight, and because the default setting for ggmap doesn't work.

library(ggplot2)
library(ggmap)
library(ggnewscale)
#register_google(key = "") Must have API Key
berkeley <- get_map(location = c(-122.261021,37.871880), zoom = 16, maptype = "satellite")
# make some fake spatial data
mu <- c(-122.261021,37.871880)
measurements <- data.frame(x = runif(30*3, mu[1]-0.005, mu[1]+0.005),
                           y = runif(30*3, mu[2]-0.005, mu[2]+0.005),
                           thing1 = rnorm(30))
measurements2 <- data.frame(x = runif(30*3, mu[1]-0.005, mu[1]+0.005),
                            y = runif(30*3, mu[2]-0.005, mu[2]+0.005),
                            thing2 = rnorm(30))
#Works
ggmap(berkeley, extent = "normal") + 
  geom_point(data = measurements, aes(x, y, color = thing1)) +
  scale_color_viridis_c(option = "D") +
  new_scale_color() +
  geom_point(data = measurements2, aes(x, y, color = thing2)) +
  scale_color_viridis_c(option = "A")
#Fails
ggmap(berkeley, extent = "device") + 
  geom_point(data = measurements, aes(x, y, color = thing1)) +
  scale_color_viridis_c(option = "D") +
  new_scale_color() +
  geom_point(data = measurements2, aes(x, y, color = thing2)) +
  scale_color_viridis_c(option = "A")
#Fails
ggmap(berkeley, extent = "panel") + 
  geom_point(data = measurements, aes(x, y, color = thing1)) +
  scale_color_viridis_c(option = "D") +
  new_scale_color() +
  geom_point(data = measurements2, aes(x, y, color = thing2)) +
  scale_color_viridis_c(option = "A")
eliocamp commented 5 years ago

Seems like the same bug that was resolved in #2, are you using the latest developement version?

tomasleon commented 5 years ago

Ahh, I see now I was using the latest release but not the latest commit, which does fix the issue. Thanks for pointing that out.