我正在尝试通过在R中使用ggmap创建简单的K均值聚类。
我跑了
if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
这是github / ggmap(https://github.com/dkahle/ggmap)的推荐。
但是,当我尝试使用
register_google(key='MyAPI')
R一直提示无法找到函数register_google()的错误。 ggmap已经安装并加载。
我从各种来源(例如:https://github.com/dkahle/ggmap/issues/143)进行了检查,这建议重新启动R会话。尽管如此,函数register_google()仍然无法正常工作。 我的代码如下:
library(ggmap)
data14=read.csv("https://raw.githubusercontent.com/fivethirtyeight/uber-tlc-foil-response/master/uber-trip-data/uber-raw-data-apr14.csv")
register_google(key = "MyAPI") **This part does not work for me**
NYCMap <- get_map('New York',maptype = 'roadmap', zoom=10)
ggmap(NYCMap) + geom_point(aes(x=Lon[], y =Lat[]), data=data14)
任何帮助将不胜感激。如果您需要更多信息,请随时告诉我。
编辑:R的输出和错误
> install.packages("ggmap")
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.4/ggmap_2.6.1.tgz'
Content type 'application/x-gzip' length 4565845 bytes (4.4 MB)
==================================================
downloaded 4.4 MB
The downloaded binary packages are in
/var/folders/2k/y418d7qs7jdbwzyv6q4sz3gc0000gn/T//RtmpmTPB4Y/downloaded_packages
> if(!requireNamespace("devtools")) install.packages("devtools")
> devtools::install_github("dkahle/ggmap", ref = "tidyup")
Downloading GitHub repo dkahle/ggmap@tidyup
✔ checking for file ‘/private/var/folders/2k/y418d7qs7jdbwzyv6q4sz3gc0000gn/T/RtmpmTPB4Y/remotes87187e0df6f3/dkahle-ggmap-4dfe516/DESCRIPTION’ ...
─ preparing ‘ggmap’:
✔ checking DESCRIPTION meta-information ...
Warning in as.POSIXlt.POSIXct(x, tz) :
unknown timezone 'zone/tz/2018g.1.0/zoneinfo/America/New_York'
─ checking for LF line-endings in source and make files
─ checking for empty or unneeded directories
Removed empty directory ‘ggmap/.github’
─ looking to see if a ‘data/datalist’ file should be added
─ building ‘ggmap_2.7.904.tar.gz’ (696ms)
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
unknown timezone 'zone/tz/2018g.1.0/zoneinfo/America/New_York'
* installing *source* package ‘ggmap’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: package ‘ggplot2’ was built under R version 3.4.4
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Warning: package ‘ggplot2’ was built under R version 3.4.4
* DONE (ggmap)
> library(ggmap)
> register_google(key = "MyAPI")
Error in register_google(key = "MyAPI") :
could not find function "register_google"
答案 0 :(得分:0)
我遇到了同样的问题。我正在使用macOS el-capitan。
以下是我要解决的步骤:
答案 1 :(得分:0)
我用了这个并且工作了。
install.packages("devtools")
devtools::install_github("dkahle/ggmap")
library(ggmap)
library(devtools)
然后您可以使用register_google()
答案 2 :(得分:0)
ggmap::register_google(key = google_api, write = TRUE)
如果已经安装了 ggmap 并且 R 找不到它,一个可能的原因是函数“register_google”被另一个包中的另一个同名函数隐藏。 添加“ggmap”使调用显式