ggplot not plotting ggmap object

こ雲淡風輕ζ 提交于 2019-12-08 03:54:51

问题


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:

# 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. Please reinstall the package that provides this extension.

I tried installing ggproto, but the error is:

> 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

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

I just don't know R well enough to know where to look next for a solution -- have ensured all packages updated.


回答1:


This is probably the version error because your code runs perfectly on my machine (R 3.3.2). devtools::install_github("dkahle/ggmap") devtools::install_github("hadley/ggplot2")

You can download packages "devtools" and install ggmap and ggplot2 from github again.



来源:https://stackoverflow.com/questions/41688270/ggplot-not-plotting-ggmap-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!