polygon创建英国地图

polygon创建英国地图

本文介绍了使用geom_polygon创建英国地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R很陌生,最近一直在尝试使用以下代码在ggplot2中创建英国的轮廓:

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

ggplot2代码的结果:

Result of ggplot2 code:

这将创建上面的地图,因为它不考虑地图的经度比例,并且将其沿x轴拉伸.英国的经度范围是-x到+ x,这在这里引起了问题.我无法找到解决此问题的任何方法,因此将不胜感激.

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.

谢谢!

推荐答案

如果您未绑定到world2Hires,则可以执行以下操作,从而获得以下信息:

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

这对您有帮助吗?

这篇关于使用geom_polygon创建英国地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:20