George George - 1 year ago 91
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:

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

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.


Answer Source

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

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

UK Map

Does that help you?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download