簡體   English   中英

ggplot 不繪制 ggmap 對象

[英]ggplot not plotting ggmap object

當我從接受的答案( 在地圖上繪制坐標)運行代碼時,我在安裝 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)

這給出了錯誤:

錯誤:GeomRasterAnn 是用不兼容的 ggproto 版本構建的。 請重新安裝提供此擴展的軟件包。

我嘗試安裝 ggproto,但錯誤是:

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

在隨后的嘗試中,錯誤是:

錯誤:ggplot2 不知道如何處理 ggmap/raster 類的數據

我可以使用以下方法繪制圖像:

plot(mapgilbert)

我試過:

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

返回以下錯誤消息:

錯誤:ggplot2 不知道如何處理 ggmap/raster 類的數據

我只是不太了解 R,無法知道下一步該去哪里尋找解決方案——確保所有軟件包都已更新。

這可能是版本錯誤,因為您的代碼在我的機器上完美運行(R 3.3.2)。 devtools::install_github("dkahle/ggmap") devtools::install_github("hadley/ggplot2")

您可以再次從 github 下載包“devtools”並安裝 ggmap 和 ggplot2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM