devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
chicago <- get_stamenmap(bbox = c(left = -88.0225, bottom = 41.5949,
right = -87.2713, top = 42.0677),
zoom = 11)
chicago_map <- ggmap(chicago)
Now I have a map of chicago, I also have a dataframe of some longitudes and altitudes,I tried many times to plot these locations on the map,don't know why it doesn't work.Please see the codes I tried below:
ggplot(longitude_latitude.new, aes(x=Longitude, y=Latitude)) +
stat_density2d(aes(fill = ..level..), alpha=0.5, geom="polygon")+
geom_point(colour="red")+
geom_path(data=chicago_map,aes(x=long, y=lat,group=group),
colour="grey50")+
scale_fill_gradientn(colours=rev(brewer.pal(7,"Spectral")))+
coord_fixed()
Error: ggplot2 doesn't know how to deal with data of class gg/ggplot
I also tried to get a map by using google API, but doesn't work...
mymap <- get_map(location = longitude_latitude.new, source = "google",
zoom = 14, maptype = "satellite")
Error in get_googlemap(center = location, zoom = zoom, maptype = maptype, :
Forbidden (HTTP 403).
Can someone tell me what to do next...I'm a beginner in R and programming,really drives me crazy...Many thanks.
I don't have points you are using but try this.
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
chicago <- get_stamenmap(bbox = c(left = -88.0225, bottom = 41.5949,
right = -87.2713, top = 42.0677),
zoom = 10)
longitude_latitude.new<- rbind(c( -87.6298,41.8781), c( -87.4298,41.9781))
longitude_latitude.new<-as.data.frame(longitude_latitude.new)
colnames(longitude_latitude.new) <- c('Longitude', 'Latitude')
chicago_map <- ggmap(chicago)
chicago_map + geom_point(data = longitude_latitude.new, aes(x = Longitude , y = Latitude, size = 5))