在 ggmap 形状上绘制 geom_sf
我正在尝试在使用 ggmap 包下载的地图上绘制地图 shapefile。但是,我收到一条神秘的错误消息和一个不太有用的回溯:
代码:
map <- get_stamenmap( bbox = c(left = 3, bottom = 48, right = 3.5, top = 49), zoom = 12, maptype = "terrain")
transformed_sample = st_transform(rpg_sf %>% filter(commune %in% smallcomslist), crs=4326)
ggmap(map) + geom_sf(data=transformed_sample, mapping=aes(fill=commune),lwd=0)
#Here transformed_sample is an object of class "sf" containing some outlines of villages in the area given by bbox.
#This returns:
ggmap(map) +
geom_sf(data=transformed_sample, mapping=aes(fill=commune),lwd=0)
坐标系已存在。添加新的坐标系,它将取代现有的坐标系。
FUN(X[[i]], ...) 中的错误:未找到对象“lon” 回溯()
10: FUN(X[[i]], ...)
9:lapply(美学,eval_tidy,数据=数据,env = env)
8: f(..., self = self)
7: l$compute_aesthetics(d, 绘图)
6: f(l = 层[[i]], d = 数据[[i]])
5: by_layer(函数(l, d) l$compute_aesthetics(d, 绘图))
4: ggplot_build.ggplot(x)
3:ggplot_build(x)
2: print.ggplot(x)
1:(函数(x,...)
UseMethod("打印"))(x)
我不知道为什么需要“lon”。有什么想法吗?
I'm trying to plot a map shapefile on top of a map downloaded using the ggmap package. However, I get a cryptic error message and a not very useful traceback:
Code:
map <- get_stamenmap( bbox = c(left = 3, bottom = 48, right = 3.5, top = 49), zoom = 12, maptype = "terrain")
transformed_sample = st_transform(rpg_sf %>% filter(commune %in% smallcomslist), crs=4326)
ggmap(map) + geom_sf(data=transformed_sample, mapping=aes(fill=commune),lwd=0)
#Here transformed_sample is an object of class "sf" containing some outlines of villages in the area given by bbox.
#This returns:
ggmap(map) +
geom_sf(data=transformed_sample, mapping=aes(fill=commune),lwd=0)
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
Error in FUN(X[[i]], ...) : object 'lon' not found
traceback()
10: FUN(X[[i]], ...)
9: lapply(aesthetics, eval_tidy, data = data, env = env)
8: f(..., self = self)
7: l$compute_aesthetics(d, plot)
6: f(l = layers[[i]], d = data[[i]])
5: by_layer(function(l, d) l$compute_aesthetics(d, plot))
4: ggplot_build.ggplot(x)
3: ggplot_build(x)
2: print.ggplot(x)
1: (function (x, ...)
UseMethod("print"))(x)
I have no idea why a "lon" is expected. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参加这个聚会已经很晚了,但是在经历了坐标参考系统更改的兔子洞之后,我通过简单地在
geom_sf()
中添加inherit.aes = FALSE
解决了类似的错误> 层。因此,您的代码将变成仅供参考,如果您经常使用 tidyverse,我建议不要命名对象
map
。当您运行library(tidyverse)
时加载的包purrr
也有一个函数map()
。Very late to this party, but after going down a rabbit hole of Coordinate Reference System changes, I solved a similar error by simply adding
inherit.aes = FALSE
in thegeom_sf()
layer. So your code would becomeAs an FYI, if you use tidyverse quite a bit, I would advise against naming an object
map
. The packagepurrr
, which gets loaded when you runlibrary(tidyverse)
also has a functionmap()
.