r - How to plot locations(longitude&altitude) on map in R?
问题描述
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.
解决方案
我没有你正在使用的积分,但试试这个。
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))
推荐阅读
- oracle - 它不工作。任何人都可以帮我解决它吗?
- python - 如何将字典输出为 csv 文件:同一列中的键和值
- regex - 如何从python3中字典中的列表中删除字符
- database - 从 CLI 使用 Cassandra 创建列族问题
- c# - Azure 是否有用于应用服务域和 SSL 测试的沙箱?
- php - 当站点用户使用 php 出现 404 错误时,如何找到尝试的 URL?
- node.js - admin.auth().verifyIdToken(idToken) 错误:在 8.0.0 之后无法使用 firebase-admin 加载默认凭据
- python - 最近邻算法?
- android - Android Firebase 检索每个孩子的前 2 个值
- html - 通过组件应用全局样式