在 R 的 ggmap 包中绘制数据时遇到问题

trouble plotting data in the ggmap package for R

我是 R 的新用户,不太熟悉这门语言。 试图在英国曼彻斯特的地图上标出鸟类记录的位置。 已成功使用以下代码创建地图

mymap<-get_map(c(lon=53.46388,lat=-2.294037),zoom=3,col="bw")

已通过 gdata 从 excel 中以 xlsx 文件形式读取电子表格,包含经度和纬度的列已分配给经度和纬度。

似乎能够 qplot lon&lat 但不能作为地图上的图层,当我尝试这样做时出现以下错误

错误:ggplot2 不知道如何处理 class 列表的数据

我现在已经尝试了如此多的代码组合,我不可能提供一条示范线来说明我是如何尝试将数据附加到我的地图上的,按照在线教程无济于事 - 是吗我的 xlsx 文件有问题吗?

已编辑:示例代码:

 #Here is what Jamie Dunning tried:
require(ggmap)
origin<-c("Worsley,Salford","Elton reservoir","Etherow country park","Blackleach country park","Low Hall,LNR, Wigan","Cheadle royal","Rhodes lodges,Middleton","Persons flash,Wigan","Sale water park","Plattfields","Higher Boarshaw","Clifton country park","Horrocks flash")  

ringing.origins<-geocode(origin) 

map<-c(get_map("Greater Manchester") 

swans.coor<-cbind(ringing.origins$lon,ringing.origins$lat)

我还没有成功绘制它们的示例。

使用 ggmap 绘图

require(ggmap)
#Get your coordinates
origin<-c("Worsley,Salford","Elton reservoir","Etherow country park","Elton reservoir","Blackleach country park","Low Hall,LNR, Wigan","Cheadle royal","Rhodes lodges,Middleton","Persons flash,Wigan","Sale water park","Plattfields","Higher Boarshaw","Clifton country park","Horrocks flash") 
ringing.origins<-geocode(origin) 

#Map of Greater Manchester
map<-get_map("Greater Manchester")
ggmap(map, extent = 'normal') +
  geom_point(aes(x = lon, y = lat), data = ringing.origins)
#Box is too small...

#Bounding box with All points
mymap<-get_map(c(lon=-2.294037,lat=53.46388),zoom=10)
ggmap(mymap, extent = 'device') +
  geom_point(aes(x = lon, y = lat), data = ringing.origins, alpha = 1)

使用 plotGoogleMaps 的另一种选择

1-获取坐标

require(ggmap)

#List places to find GPS coordinates for:
    origin<-c("Worsley,Salford","Elton reservoir","Etherow country park","Elton reservoir","Blackleach country park","Low Hall,LNR, Wigan","Cheadle royal","Rhodes lodges,Middleton","Persons flash,Wigan","Sale water park","Plattfields","Higher Boarshaw","Clifton country park","Horrocks flash")

#Get coordinates via geocode function    
    ringing.origins<-geocode(origin)

#Put these coordinates in a data frame for creating an SP object later 
    df <- as.data.frame(origin)
    row.names(df) <- 1:nrow(df)

2- 创建空间对象

require(sp)
#Coordinates must be numeric and binded together as one element and rows numbered:
    ringing.origins$lon <- as.numeric(ringing.origins$lon)
    ringing.origins$lat <- as.numeric(ringing.origins$lat)
    coord <- cbind(ringing.origins$lon,ringing.origins$lat)
    row.names(coord) <- 1:nrow(coord)
#Define a mapping projection
    AACRS <- CRS("+proj=longlat +ellps=WGS84")
#Creating a spatial object of "df" using the binded coordinates "coord":
    Map2 <- SpatialPointsDataFrame(coord, df, proj4string = AACRS, match.ID = TRUE) 

3-创建交互式 html googlemap:

 require(plotGoogleMaps)
    #Simple Map
    plotGoogleMaps(Map2)
    #Map with some options, filename creates a file in the working directory.
    plotGoogleMaps(Map2, mapTypeId="ROADMAP", colPalette="red", legend=FALSE, filename="Swan_Map.htm")