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
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.