簡體   English   中英

ggmap 和空間數據繪圖問題

[英]ggmap and spatial data plotting issue

我正在嘗試更新我在 Google API 時代之前繼承的一些舊代碼,以做一個相當簡單(我認為)的圖。

當我到達情節時,我的數據包含 50 個緯度、經度的三元組,以及該位置的 $K 投資額。

head(investData)
  amount latitude longitude
1 1404   42.45909 -71.27556
2 1      42.29076 -71.35368
3 25     42.34700 -71.10215
4 1      40.04492 -74.58916
5 15     43.16431 -75.51130

在這一點上我使用以下

register_google(key = "###myKey###")   #my actual key here

USAmap <- qmap("USA",zoom=4)

USAmap + geom_point(data=investData, aes(x=investData$longitude, y=investData$latitude,size=investData$amount))

我一直在努力與 Google 建立帳戶和啟用 API,所以我完全有可能只是未能啟用我需要的東西。 我啟用了地理編碼、地理定位和地圖靜態 API。

我在控制台得到以下輸出

Source : https://maps.googleapis.com/maps/api/staticmap?center=USA&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
Source : https://maps.googleapis.com/maps/api/geocode/json?address=USA&key=xxx

但我沒有情節。

如果我只是跑

qmap("USA", zoom=4)

我得到了我期望的地圖。 但是當我嘗試覆蓋投資數據時,我得到了zilch。 把這個交給我的人告訴我,它在 2017 年有效......

知道我哪里出錯了嗎?

如果您通過源函數或運行命令(從 RStudio 內部)運行腳本,則必須在 ggplot 命令上顯式調用print函數。 例如:

print(USAmap + geom_point(data=investData, aes(x=longitude, y=latitude,size=amount)))

正如卡米爾提到的,不需要aes里面的$

暫無
暫無

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

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