ggplot不绘制ggmap对象 [英] ggplot not plotting ggmap object
问题描述
当我从接受的答案(在地图上绘制坐标)运行代码时, ,在安装ggmap后第一次运行时会出现以下错误消息:
#加载所需的软件包
library( ggplot2)
library(ggmap)
#用你的经纬度点创建一个样本data.frame
lon <-c(-38.31,-35.5)
lat < - c(40.96,37.5)
df < - as.data.frame(cbind(lon,lat))
#得到地图
mapgilbert< ; - get_map(location = c(lon = mean(df $ lon),lat = mean(df $ lat)),zoom = 4,
maptype =satellite,scale = 2)
$
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,但错误是:
>在install.packages中警告:
package'ggproto'不可用(for R version 3.3.2)
在随后的尝试中,错误是:
错误:ggplot2不知道如何处理类ggmap / raster的数据
我可以使用以下图表绘制图片:
plot(mapgilbert)
我试过了:
map2< - get_map(Rotorua,zoom = 16)
ggmap(data = map2)
返回错误信息:
$ b
错误:ggplot2 doesn '不知道如何处理类ggmap / raster的数据
我只是不知道R到哪里去看解决方案
这可能是版本错误,因为您的代码完全运行在我的机(R 3.3.2)。
devtools :: install_github(dkahle / ggmap)
devtools :: install_github(hadley / ggplot2)
您可以下载软件包devtools,并再次从github安装ggmap和ggplot2。
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.
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.
这篇关于ggplot不绘制ggmap对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!