r - ggplot 不绘制 ggmap 对象

标签 r ggplot2 ggmap ggproto

当我从接受的答案( Plot coordinates on map )运行代码时,在安装 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)

这给出了错误:

Error: GeomRasterAnn was built with an incompatible version of ggproto. Please reinstall the package that provides this extension.

我尝试安装ggp​​roto,但错误是:

> Warning in install.packages :
  package ‘ggproto’ is not available (for R version 3.3.2)

在后续尝试中,错误为:

Error: ggplot2 doesn't know how to deal with data of class ggmap/raster

我可以使用以下方法绘制图像:

plot(mapgilbert)

我尝试过:

map2 <- get_map("Rotorua", zoom = 16)
ggmap(data = map2)

返回以下错误消息:

Error: ggplot2 doesn't know how to deal with data of class ggmap/raster

我只是不太了解 R,不知道下一步该去哪里寻找解决方案——已确保更新所有软件包。

最佳答案

这可能是版本错误,因为您的代码在我的机器上完美运行(R 3.3.2)。 devtools::install_github("dkahle/ggmap") devtools::install_github("hadley/ggplot2")

您可以再次从 github 下载“devtools”包并安装 ggmap 和 ggplot2。

关于r - ggplot 不绘制 ggmap 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41688270/

相关文章:

r - 在 RMarkdown 文档中添加 ggvis 绘图会使 knit::kable 输出渲染不正确

r - 在 ggplot2 r 中添加轴刻度和标签

r - ggplot2:显示x轴标签的类别和子类别

r - 如何使用 R 和带状图 + 线图来显示 2 路网格

R ggplot2position_dodge()`需要非重叠的x间隔警告

r - ggmap 扩展缩放或边界

text - 为什么字段分隔符必须只有一个字节?

r - ggmap:注释错误

R 根据需要创建一个覆盖美国 basemap 和其他空间图层的空间气泡图

r - 删除空部分\value R 包检查说明