4

R と ggmap パッケージを使用してデータフレームを視覚化したいと考えています。

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

私は何を間違っていますか?

4

1 に答える 1

7

次の 3 つの問題があります。

  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)

結果のマップ:

ここに画像の説明を入力

于 2014-03-17T16:06:20.473 に答える