Creating a UK map with geom_polygon

安稳与你 提交于 2019-12-12 09:55:20

问题


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:

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!


回答1:


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()

Does that help you?



来源:https://stackoverflow.com/questions/40673461/creating-a-uk-map-with-geom-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!