# Plotting Geographical Grid from Long/Lat Coordinates in R

I have a file of coordinates (Long/Lat) that should enable me to plot a series of 10km grid squares covering the UK. However, for each grid square I have five sets of coordinates by way of plotting the four corners of the square (starting bottom left and moving round clockwise) and returning to the starting point (so the first and last sets of coordinates for each square are identical), as follows:

``````> head(Coordinates)
long      lat order grid resolution

1 -2.001839 60.68321     1 HP00         10
2 -2.001845 60.77299     2 HP00         10
3 -1.818269 60.77287     3 HP00         10
4 -1.818774 60.68309     4 HP00         10
5 -2.001839 60.68321     5 HP00         10
6 -2.001845 60.77299     1 HP01         10
``````

I've been exploring options for plotting the grid (e.g. geom_rect, geom_raster etc.), but the fact that I have five sets of coordinates for each square ('order' in the table above) seems to be complicating matters! That said, I'm very new to R, so may well be missing something that's obvious to others. Can anyone suggest how I might best go about using the data to generate/plot the complete set of grid squares, please?

• If these grid squares are 10km squares in the Ordnance Survey National Grid system then maybe you should convert them to a raster object. I just did a quick transform of the points in your example and they are on the corners of the 10km grid system... – Spacedman Apr 3 '19 at 16:25

`geom_polygon()` is what you are looking after. The line
``````ggplot(Coordinates) + geom_polygon(aes(long, lat, group = grid))