绘制地理编码:ggmap错误 [英] Plot geocode: ggmap error

查看:50
本文介绍了绘制地理编码:ggmap错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用R和ggmap包可视化一个数据框.

I want to visualize a dataframe with R and the ggmap package.

df:

| lon       | lat       |
|-----------|-----------|
| 6.585863  | 51.09021  |
| 8.682.127 | 50.11092  |
| 7.460.367 | 5.152.755 |

我创建了一个地图

mapImageData <- get_googlemap(
+   "Germany", 
+   zoom=15
+ )

然后要添加地理编码:

ggmap(mapImageData) +
+     geom_point(aes(x=lon, y=lat), data=df, colour="red", size=5)

但是我得到了错误:错误:geom_point需要以下缺失的美学特征:x,y

我在做什么错了?

推荐答案

您遇到三个问题:

  1. 在某些价值和意义上不止一个沉思点小数点可能不在正确的位置(另请参阅我的评论)
  2. 地图位于错误的位置
  3. 缩放级别很高

让我们解决此问题:

# Get the right data
ger <- read.table(text="lon lat
6.585863 51.09021
8.682127 50.11092
7.460367 51.52755", header = TRUE, strip.white = TRUE)

# Finding a good centerpoint
mean(ger$lon) # outcome: 7.576119
mean(ger$lat) # outcome: 50.90956

# Get the map; you might have to try several zoomlevels te get the right one
library(ggmap)
mapImageData <- get_googlemap(center = c(lon = 7.576119, lat = 50.90956), zoom=8)

# Plot the points on the map
ggmap(mapImageData) +
  geom_point(data=ger, aes(x=lon, y=lat), colour="red", size=6, alpha=.6)

生成的地图:

这篇关于绘制地理编码:ggmap错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆