2

I have a shapefile with shapelength and shapearea, and would like to convert to WGS84 to use with ggmap.

enter image description here

Eventually, I would like to get plot google map of individual regions of the shapefile, and overlay it with other date

What can I use in R program to do this, i.e. convert to WGS84?

Rhonda
  • 301
  • 1
  • 8

1 Answers1

4

Use functions from the sp and rgdal packages. Assuming your shape file is named myshp

library(sp)
library(rgdal)
proj4string(myshp) # Gives the CRS of the data 
myshp=spTransform(myshp,CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")) # To convert it to WGS84

ggplot2 input has to be a DataFrame, to convert a SpatialDataFrame to a DataFrame named mydf, run

library(ggplot2)
mydf=fortify(myshp,byid="your id variable") # Converting the SpatialDataFrame to a DataFrame
myshp$id=row.names(myshp) # Adding your SpatialDataFrame data to the DataFrame
mydf=merge(mydf,myshp@data,by="id",all=T)
goclem
  • 208
  • 1
  • 8