Dear ggplot2 list,
I am reproducing two ggmap examples from Kahle & Hadley's example, but do not get the same.
In example one, I got two legends instead of one. In example two, overlay() function is not found.
Map and dataset are attached. I guess some arguments have changed since then?
Here's example 1 code:
houston <- get_map("houston", zoom = 14)
HoustonMap <- ggmap(houston, extent = "device", legend = "topleft")
HoustonMap + stat_density2d(
aes(x = lon, y = lat, fill = ..level..,
alpha = ..level..),
size = 2, bins = 4, data = crime,
geom = "polygon")
Here's example 2 code (continues from example 1):
overlay <- stat_density2d(
aes(x = lon, y = lat, fill = ..level..,
alpha = ..level..),
bins = 4, geom = "polygon",
data = violent_crimes)
HoustonMap + overlay + inset(
grob = ggplotGrob(ggplot() +
overlay + theme_inset()),
xmin = -95.35836, xmax = Inf,
ymin = -Inf, ymax = 29.75062
)
> Error: object 'overlay' not found
Could someone let me know what I should do in this case? Thank you so much!
Mike