Mic*_*hał 10 google-maps r data-analysis ggplot2 ggmap
我们假设我使用ggmap包生成伦敦地图:
library(ggmap)
library(mapproj)
map <- get_map(location = "London", zoom = 11, maptype = "satellite")
p <- ggmap(map)+
theme(legend.position = "none")
print(p)
Run Code Online (Sandbox Code Playgroud)
现在我想在这个图中添加一个带有一些中心坐标的圆(比方说:lon = -0.1,lat = 52.23)和半径,例如以公里为单位.我尝试使用类似问题的解决方案(用ggplot2绘制一个圆圈),你可以在这里添加一个这样的语句:
p <- p + annotate("path",
x = xc+r*cos(seq(0,2*pi,length.out=100)),
y = yc+r*sin(seq(0,2*pi,length.out=100)))
Run Code Online (Sandbox Code Playgroud)
它有效,但由于规模不同,圆圈实际上不是圆形.是否可以正确绘制它?任何帮助,将不胜感激!
编辑:我找到了使用不同包的解决方案(https://gis.stackexchange.com/questions/119736/ggmap-create-circle-symbol-where-radius-represents-distance-miles-or-km),输出结果是正确.不过,如果有人知道如何使用ggmap,请分享它.
您可以从地图对象获取经度和纬度跨度:
> m = get_map(location="london", zoom=11, maptype="satellite")
> corners = attributes(m)$bb
> delta.x = corners["ur.lon"] - corners["ll.lon"]
> delta.y = corners["ur.lat"] - corners["ll.lat"]
Run Code Online (Sandbox Code Playgroud)
然后相应地调整你的路径。另请注意,该ggmap包有一个名为的函数LonLat2XY(请参阅参考资料)。
| 归档时间: |
|
| 查看次数: |
1525 次 |
| 最近记录: |