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 at 16:25

geom_polygon() is what you are looking after. The line

ggplot(Coordinates) + geom_polygon(aes(long, lat, group = grid))

should do the trick.

ps: next time, make your data available so that we can be more precise on addressing you issue :)

  • Thanks - that does indeed 'do the trick' - and I note your comment about data for next time! – NigelH Apr 4 at 20:49
  • great, good to hear it works! – Bruno Conte Leite Apr 6 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.