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)
现在我有芝加哥地图,也有一些经度和海拔高度的数据框,我尝试了很多次在地图上绘制这些位置,不知道为什么它不起作用。请查看代码在下面尝试过:
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
我也尝试使用Google API获取地图,但是不起作用...
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).
有人可以告诉我下一步该怎么做...我是R和编程的初学者,真的让我发疯了...非常感谢。
答案 0 :(得分:0)
我没有您要使用的积分,请尝试一下。
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))