【问题标题】:ggmap and spatial data plotting issueggmap和空间数据绘图问题
【发布时间】:2020-02-19 12:14:34
【问题描述】:

我正在尝试更新我在 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 年有效......

知道我哪里出错了吗?

【问题讨论】:

  • 我无法重现,但可以试试这个:print(USAmap + geom_point(data=investData, aes(x=longitude, y=latitude,size=amount)))
  • 也无法复制。 Don't use $ inside aes。除此之外,更新软件包,重启 R,然后再试一次?
  • print 做到了....如果您想回答我会很乐意接受它。是的,不知道为什么 $ 在 aes 中。我也会解决的。

标签: r google-maps google-api ggmap


【解决方案1】:

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

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

正如卡米尔所说,aes 中不需要 $

【讨论】:

    猜你喜欢
    • 2014-11-06
    • 2018-09-27
    • 2015-12-08
    • 2020-11-19
    • 2020-09-02
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多