user2151703
user2151703

Reputation: 15

plotGoogleMaps help: plotting latitude longitude values

I am trying to use plotGoogleMaps to plot latitude and longitude values

The code is:

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')

I am getting this error:

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

Please help!

I am using plotGoogleMaps version 1.3

Upvotes: 0

Views: 1744

Answers (1)

Simon O&#39;Hanlon
Simon O&#39;Hanlon

Reputation: 59970

Your problem is that your .csv contains only columns for Latitude and Longitude in which case the coordinates() function will return a SpatialPoints object rather than a SpatialPointsDataFrame which seems to be required of plotGoogleMaps().

You can coerce it to an spdf by making a dummy varaible for the dataframe. An ID number for each point seems like a good idea. Try these steps in this order (please note that plotGoogleMaps saves the resulting plot as html not 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')

Upvotes: 2

Related Questions