plotGoogleMaps help:绘制纬度经度值

时间:2013-03-09 14:43:16

标签: r google-maps geolocation gis

我正在尝试使用plotGoogleMaps绘制纬度和经度值

代码是:

streetCrime = read.csv("C:/Users/DAKSHA/Google Drive/BE Project/Daksha/Datasets/BaltimoreHomicide.csv")

coordinates(streetCrime) = ~Longitude + Latitude
proj4string(streetCrime) = CRS("+proj=longlat +datum=WGS84")
m<-plotGoogleMaps(streetCrime,filename='myMap1.jpg')

我收到此错误:

Error in plotGoogleMaps(streetCrime, filename = "myMap1.jpg") :
   no slot of name "data" for this object of class "SpatialPoints"

请帮忙!

我正在使用plotGoogleMaps 1.3版

1 个答案:

答案 0 :(得分:2)

您的问题是.csv仅包含LatitudeLongitude的列,在这种情况下coordinates()函数将返回SpatialPoints个对象,而不是SpatialPointsDataFrame似乎需要plotGoogleMaps()

您可以通过为数据帧进行虚拟变量来将其强制转换为spdf。每个点的ID号似乎都是个好主意。按此顺序尝试这些步骤(请注意,plotGoogleMaps将结果图保存为html而不是jpg):

streetCrime = read.csv("C:/Users/DAKSHA/Google Drive/BE Project/Daksha/Datasets/BaltimoreHomicide.csv")
coordinates(streetCrime) = ~ Longitude + Latitude
proj4string(streetCrime) = CRS("+proj=longlat +datum=WGS84")
streetCrime <- SpatialPointsDataFrame( streetCrime , data = data.frame( ID = row.names( streetCrime ) ) )
m <- plotGoogleMaps(streetCrime , filename='myMap1.html')