ggmap和空间数据绘图问题

问题描述 投票:0回答:1

我正在尝试更新我在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)

我得到了我期望的地图。但是,当我尝试覆盖投资数据时,我却变得迟钝了。告诉我的人告诉我它在2017年有效...

知道我要去哪里错了吗?

r google-maps google-api ggmap
1个回答
0
投票

如果您通过源函数或通过运行命令(从RStudio内部)运行脚本,则必须在ggplot命令上显式调用print函数。例如:

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

正如卡米尔提到的,不需要$内的aes

© www.soinside.com 2019 - 2024. All rights reserved.