[英]R: Error in get_map()/get_googlemap() from ggmap
我正在尝试使用 GGmap 按州创建车辆车祸图。 地图上的点的大小取决于该州的车祸数量。
特别是,我正在尝试重新创建此博客文章的可视化集群部分中显示的 usa-plot。
但是,每当我尝试创建地图时,都会出现此错误。
Error in aperm.default(map, c(2, 1, 3)) :
invalid first argument, must be an array
我已经设置了 Google API 并看到它正在接收点击。 我也启用了它并拥有密钥。
此外,我已经使用以下命令从 github 帐户安装了 GGmap:
devtools::install_github("dkahle/ggmap", ref = "tidyup", force=TRUE)
因为 CRAN 没有更新。
我也多次重新启动并退出 R,但错误仍然存在。
即使我只是简单地运行:
get_map()
它仍然导致错误:
Error in aperm.default(map, c(2, 1, 3)) :
invalid first argument, must be an array
下面是我的代码,它类似于博客文章中的代码:
mydata$State <- as.character(mydata$State)
mydata$MV.Number = as.numeric(mydata$MV.Number)
mydata = mydata[mydata$State != "Alaska", ]
mydata = mydata[mydata$State != "Hawaii", ]
devtools::install_github("dkahle/ggmap", ref = "tidyup", force=TRUE)
library(ggmap)
ggmap::register_google(key = "...") #my key is here
for (i in 1:nrow(mydata)) {
latlon = geocode(mydata[i,1])
mydata$lon[i] = as.numeric(latlon[1])
mydata$lat[i] = as.numeric(latlon[2])
}
mv_num_collisions = data.frame(mydata$MV.Number, mydata$lon, mydata$lat)
colnames(mv_num_collisions) = c('collisions','lon','lat')
usa_center = as.numeric(geocode("United States"))
USAMap = ggmap(get_googlemap(center=usa_center, scale=2, zoom=4),
extent="normal")
USAMap +
geom_point(aes(x=lon, y=lat), data=mv_num_collisions, col="orange",
alpha=0.4, size=mv_num_collisions$collisions*circle_scale_amt) +
scale_size_continuous(range=range(mv_num_collisions$collisions))
我希望在地图像输出这
但我似乎无法通过这个错误。
如果有人可以提供帮助,那就太好了。
如果您需要更多信息,请告诉我。
谢谢你。
此错误是由于 google 密钥没有为该密钥启用适当的 API 活动。
进入谷歌 API 控制台并启用 API“Maps Static API”,它应该适合你。
编辑:2020 年 1 月 - 我正在做一些类似的工作,发现一个类似的 API 失败了,因为必须将帐单信息添加到 Google Cloud 控制台中的项目中才能起作用。
有必要在Google API中确认您的信用卡,这样,您的API密钥就会被激活,您可以正常使用ggmap
确保启用计费。 您不必限制 api,但请确保启用所有您需要的 api。 如果您想搜索位置名称,除了静态地图之外,您还需要地理编码 API。 来自 CRAN 的 ggmap 现在可以了(不需要 github 版本)。
我遇到了同样的错误,并遵循了评论中提到的说明。 我补充说:
我用devtools::install_github("dkahle/ggmap")
从源代码安装了ggmap
。 然后,我使用register_google(key = "xxx")
注册了我的密钥,确认该密钥可用于has_google_key()
。
然而,我在调用get_map
时仍然会收到
Error in aperm.default(map, c(2, 1, 3)) : invalid first argument, must be an array In addition: Warning message: In get_googlemap(center = location, zoom = zoom, filename = filename) : HTTP 400 Bad Request
我还将get_map
的源get_map
为“osm”而没有任何成功。
任何进一步的想法来解决这个问题,我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.