[英]ggplot not plotting ggmap object
When I run the code from the accepted answer ( Plot coordinates on map ), I get the following error message on the first run after installing ggmap:当我从接受的答案( 在地图上绘制坐标)运行代码时,我在安装 ggmap 后第一次运行时收到以下错误消息:
# loading the required packages
library(ggplot2)
library(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(-38.31,-35.5)
lat <- c(40.96, 37.5)
df <- as.data.frame(cbind(lon,lat))
# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
maptype = "satellite", scale = 2)
# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
which gives the error:这给出了错误:
Error: GeomRasterAnn was built with an incompatible version of ggproto.
错误:GeomRasterAnn 是用不兼容的 ggproto 版本构建的。 Please reinstall the package that provides this extension.
请重新安装提供此扩展的软件包。
I tried installing ggproto, but the error is:我尝试安装 ggproto,但错误是:
> Warning in install.packages :
package ‘ggproto’ is not available (for R version 3.3.2)
On subsequent attempts the error is:在随后的尝试中,错误是:
Error: ggplot2 doesn't know how to deal with data of class ggmap/raster
错误:ggplot2 不知道如何处理 ggmap/raster 类的数据
I can plot the image using:我可以使用以下方法绘制图像:
plot(mapgilbert)
I tried:我试过:
map2 <- get_map("Rotorua", zoom = 16)
ggmap(data = map2)
which returned the follow error message:返回以下错误消息:
Error: ggplot2 doesn't know how to deal with data of class ggmap/raster
错误:ggplot2 不知道如何处理 ggmap/raster 类的数据
I just don't know R well enough to know where to look next for a solution -- have ensured all packages updated.我只是不太了解 R,无法知道下一步该去哪里寻找解决方案——确保所有软件包都已更新。
This is probably the version error because your code runs perfectly on my machine (R 3.3.2).这可能是版本错误,因为您的代码在我的机器上完美运行(R 3.3.2)。
devtools::install_github("dkahle/ggmap")
devtools::install_github("hadley/ggplot2")
devtools::install_github("dkahle/ggmap")
devtools::install_github("hadley/ggplot2")
You can download packages "devtools" and install ggmap and ggplot2 from github again.您可以再次从 github 下载包“devtools”并安装 ggmap 和 ggplot2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.