Search code examples
rggplot2geospatialrgdalr-sp

How to convert Longitude / Latitude coordinate in utm32 for plotting with ggplot2?


I made a choropleth map with a utm32-shapefile and now, I want to add a second layer with data from another data frame. This second data frame only has Lon/Lat-information. I want to convert the Lon/Lat to utm32 coordinates, so I can use them with ggplot2 as another - convergent - layer.

The data frame looks like this:

GPS_Lat   GPS_Lon   Index
51,133    14,683    12.75

First, I use gsub to recode the "," to ".". Then I convert the variables to numeric.

#Then I tried to define the variables as Lon/Lat-Coordinates
cord.dec<-SpatialPointsDataFrame(cbind(plot.eeg$GPS_Lon,plot.eeg$GPS_Lat),data=plot.eeg,proj4string=CRS("+proj=longlat"))

#Then i tried to convert them to utm32
cord.UTM<-spTransform(cord.dec,CRS("+init=epsg:4326"))

It didn't work. I just get a copy of my Lat/Lon-variables.

I didn't find a good documentation on how to do this. Perhaps somebody else can help me?


Solution

  • Your CRS string is incorrect: EPSG:4326 is WGS84 longlat (see here); Try EPSG:32632 instead.