简体   繁体   English

在R中使用ggmap进行绘图

[英]Issue plotting with ggmap in R

I am trying to make a map using ggmap pulling the image from google. 我正在尝试使用ggmap从Google提取图像来制作地图。 Below is my code where I am trying to pull a plot of Utah and then plot it. 下面是我尝试绘制犹他州的一块图,然后对其进行绘图的代码。

The plot will not be made because of the error that I receive: "error in as.vector(y) : attempt to apply non-function." 由于收到的错误而无法绘制该图:“ as.vector(y)中的错误:尝试应用非功能。”

Any clue on what is going on and why it won't work? 关于发生了什么以及为什么它不起作用的任何线索?

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
#pull map of Utah

Ut.map <- get_map(location=c(-111, 39.5), zoom=7, maptype="roadmap")

Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=39.5,-111&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false

ggmap(Ut.map)

Error in as.vector(y) : attempt to apply non-function

Edit: 11/14/2016 4:00 pm 编辑:11/14/2016 4:00 pm

I updated R, Rstudio, and ggplot2. 我更新了R,Rstudio和ggplot2。 Now I receive this error message when I try to load ggplot2: 现在,当我尝试加载ggplot2时,我收到此错误消息:

library(ggplot2)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘ggplot2’

I tried to install Rcpp and I receive this message: 我尝试安装Rcpp并收到以下消息:

install.packages("Rcpp")
Installing package into ‘C:/Users/justi/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.3/Rcpp_0.12.7.zip'
Content type 'application/zip' length 3265506 bytes (3.1 MB)
downloaded 3.1 MB

package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning in install.packages :
unable to move temporary installation ‘C:\Users\justi\Documents\R\win-     
library\3.3\file150426f11cb7\Rcpp’ to ‘C:\Users\justi\Documents\R\win-  
library\3.3\Rcpp’

The downloaded binary packages are in
C:\Users\justi\AppData\Local\Temp\RtmpesXik0\downloaded_packages

Now I can't run anything related to ggplot or anything. 现在,我无法运行与ggplot相关的任何内容。 My new R details are: 我的新R详细信息是:

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

Fixed the problem! 解决了问题! So another person had issues installing the Rcpp package ( https://github.com/hadley/dplyr/issues/2002 ) 因此,另一个人在安装Rcpp软件包时遇到了问题( https://github.com/hadley/dplyr/issues/2002

Following their advise, I suspended my antivirus coverage and was able to easily install all packages with no errors. 按照他们的建议,我暂停了防病毒程序的覆盖范围,并能够轻松安装所有软件包而没有任何错误。

Following this complete reinstall of R, Rstudio, ggplot2, and ggmap, I was finally able to get the plot with no issues. 完全重新安装R,Rstudio,ggplot2和ggmap之后,我终于可以毫无问题地获得该图了。

Helpful advise for anyone in the future, try deactivating your antivirus to install updates to packages! 将来对任何人都有用的建议,请尝试停用您的防病毒软件以安装软件包的更新!

I had the same problem just this morning, with code that worked for me last week. 今天早上,我遇到了同样的问题,上周的代码对我有用。 The only change I can think of is an accidental reinstall of the ggmap package. 我能想到的唯一更改是意外重新安装了ggmap软件包。

After updating the ggplot2 package I was actually able to generate a map and no longer received the error, hope that helps. 更新ggplot2软件包后,我实际上能够生成一个映射,并且不再收到错误,希望对您有所帮助。

I had same error message, so I tried to update ggplot2 package and it works - now version 2.2.0, R in version x64 3.3.1. 我有同样的错误消息,所以我尝试更新ggplot2软件包,并且它可以工作-现在版本2.2.0,R在x64 3.3.1版本中。 Hope it will also work for you. 希望它也能为您服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM