R:GGMAP如何在生成的地图上添加LON/LAT点?
我正在尝试将数据点放在地图上。但是我会收到以下错误: AREAMAP + GEOM_POINT中的错误(data = d,mapping = aes(x = lon,y = lat),: 另外,非数字参数向二进制操作员:警告消息: “+”的不兼容方法(“ ops.raster”,“+.gg”)
我已经搜索了整个平台以寻求解决方案,但到目前为止,我未能在生成的地图上投射要点。如果您可以帮助我,我的脚本:
library(ggmap)
library(ggplot2)
> area <- read.csv("area.csv", head = T, sep = ",")
> area #area.csv
species lat lon
1 primavera 20.64122 -103.5897
2 primavera 20.60023 -103.5341
3 primavera 20.62951 -103.5282
4 primavera 20.64517 -103.6449
5 primavera 20.68247 -103.5474
> save(area, file="area.rda")
> areabox <- make_bbox(lat = lat,
+ lon = lon,
+ data = area,
+ f = 1)
> areabox
left bottom right top
-103.76159 20.51799 -103.41154 20.76472
> # Ver los registros
> fix(area)
> areamapa <- get_map(location = areabox,
+ source = "stamen",
+ maptype = "terrain")
> d<-data.frame(lat=c(20.65728,20.70386),
+ lon=c(-103.62736,-103.53156))
> d # puntos
lat lon
1 20.65728 -103.6274
2 20.70386 -103.5316
> #incluir puntos georreferenciados
> points<- areamapa +
+ geom_point(data = d,
+ mapping = aes(x = lon, y = lat),
+ size = 2,
+ colour = "red")
Error in areamapa + geom_point(data = d, mapping = aes(x = lon, y = lat), :
non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("Ops.raster", "+.gg") for "+"
I am trying to place data points on a map. But I get the following error:
Error in areamap + geom_point(data = d, mapping = aes(x = lon, y = lat), :
non-numeric argument to binary operator In addition: Warning message:
Incompatible methods ("Ops.raster", "+.gg") for "+"
I have searched the entire platform for a solution, but so far failed to project the points on the generated map. My script in case you can help me:
library(ggmap)
library(ggplot2)
> area <- read.csv("area.csv", head = T, sep = ",")
> area #area.csv
species lat lon
1 primavera 20.64122 -103.5897
2 primavera 20.60023 -103.5341
3 primavera 20.62951 -103.5282
4 primavera 20.64517 -103.6449
5 primavera 20.68247 -103.5474
> save(area, file="area.rda")
> areabox <- make_bbox(lat = lat,
+ lon = lon,
+ data = area,
+ f = 1)
> areabox
left bottom right top
-103.76159 20.51799 -103.41154 20.76472
> # Ver los registros
> fix(area)
> areamapa <- get_map(location = areabox,
+ source = "stamen",
+ maptype = "terrain")
> d<-data.frame(lat=c(20.65728,20.70386),
+ lon=c(-103.62736,-103.53156))
> d # puntos
lat lon
1 20.65728 -103.6274
2 20.70386 -103.5316
> #incluir puntos georreferenciados
> points<- areamapa +
+ geom_point(data = d,
+ mapping = aes(x = lon, y = lat),
+ size = 2,
+ colour = "red")
Error in areamapa + geom_point(data = d, mapping = aes(x = lon, y = lat), :
non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("Ops.raster", "+.gg") for "+"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用
get_map
时,它返回ggmap
对象(分类栅格对象)。要绘制它,请尝试使用ggmap(areamapa)
。这是添加点的完整示例:output
When you call
get_map
it returns aggmap
object (classed raster object). To plot it, try usingggmap(areamapa)
. Here is the complete example with points added:Output