Plotting UTM / Coordinates

Viewed 589

I am new to R programming, I have a csv/excel file of 20 towns in a country which contains the in the below format,

Towns UTM Cordinates UTM Cordinaetes
xxxxxxxx 1377777 249514
yyyyyyyy 142145 228942

I am unable to plot them into a map, Does anyone have any idea of how t plot these UTM Cordinates. Is it possible to plot towns in R programming with UTM? If so can anyone help me out here. I have the shape file for the country with me as well. But I am not sure how to process.

myfilepath <- file.choose()
Cordinates<-read.csv(myfilepath,header=TRUE)
Cordinates
str(Cordinates)
library(rgdal)
library(sp)
library(data.table)
library(ggplot2)
library(tibble)
myfilepath <- file.choose()
Shapefile<-readOGR(myfilepath)
plot(Shapefile)
ggmap(Shapefile)+geom_point(aes(x=Easting,y=Northing,col=Cordinates))

Any help would be appreciated.

2 Answers

Here is a sf-solution, making use of all the hard work from @Dave2e to find the correct coordinate system used...

#convert to simple feature
library( sf )
mysf <- sf::st_as_sf( mydata, coords = c("Easting", "Northing"), crs = 29902)

#plot for visual inspection
mapview::mapview(mysf)

enter image description here

The trick is to determine the grid system used. After much searching the code for standard Republic of Ireland grid is epsg:29902

The first step is to transform the Irish grid coordinates to a standard latitude and longitude. This is accomplished with the "rgdal" library.

library(rgdal)    

points <- read.table(header=TRUE, text = "Towns Easting Northing 
                      Belclare 137777 249514
                      Carnmore 142145 228942")

#Pull out the location columns and rename
point <- points[,2:3]
names(point) <-c('x', 'y')

#convert to corrdinates and define initial coordinates systems
coordinates(point) <- c('x', 'y')
proj4string(point)=CRS("+init=epsg:29902")  #29903 is the grid for Ireland

#Transform the Ireland's grid to longitude & latitude
coord<-spTransform(point,CRS("+init=epsg:4326"))
coord

This will transform your list of coordinates, please search this site on how to plot to a map. There are many options available.

Related