George George - 19 days ago 5
R Question

Creating a UK map with geom_polygon

I am quite new to R and have recently been trying to create an outline of the UK in ggplot2 with the following code:

library(ggplot2)
UK <- map_data("world2Hires", region = "UK")
ggplot() + geom_polygon(data = UK, aes(x = long, y = lat, group = group)) +
coord_map()


Result of ggplot2 code:

Result of ggplot2 code

This creates the map above as it does not take into account the longitude scale of the map and stretches it across the x-axis. The UK has a longitude that spans from -x to +x which is causing the problem here. I have not been able to find any way of fixing this so any help would be much appreciated.

Thanks!

Answer

If you are not bound to world2Hires, you can do the following, which gives me the following:

library(ggplot2)
UK <- map_data(map = "world", region = "UK") # changed map to "world"
ggplot(data = UK, aes(x = long, y = lat, group = group)) + 
  geom_polygon() +
  coord_map()

UK Map

Does that help you?