簡體   English   中英

使用R在谷歌地圖上繪制點

[英]Plotting points over google map using R

我試圖在R中的谷歌地圖上繪制一些經度和緯度點但是我收到錯誤消息:

不知道如何自動為data.frame類型的對象選擇比例。 默認為連續錯誤:美學必須是長度為1或與dataProblems相同的長度:sg

這是我的R代碼:

sg <- read.csv("sg.csv")
head(sg)

library(ggmap)
library(mapproj)
map <- get_map(location = 'Midway Point, Tasmania', zoom = 12)
ggmap(map)

mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, data = sg, alpha = .5))
mapPoints

數據如下所示:

> head(sg)
   ref       lat      lon
1 Male -42.80429 147.4954
2 Male -42.80367 147.4951
3 Male -42.80521 147.4919
4 Male -42.80525 147.4925
5 Male -42.80501 147.4955
6 Male -42.80414 147.4959

誰能幫我嗎?? 非常感謝。

閱讀錯誤消息是值得的。 我是一個非常缺乏經驗的ggplot用戶,並且同樣適用於ggmap。 讀取的錯誤消息: Error: Aesthetics must either be length one, or the same length as the dataProblems:sg 所以我查看了?ggmap中的示例,並決定1)數據參數不應該在aes()調用中,2)你需要aes的第三個參數,所以我選擇顏色並且“工作”。

 mapPoints <- ggmap(map) + 
    geom_point(aes(x = lon, y = lat, color=ref), data = sg, alpha = .5)
 mapPoints

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM