我有一个大伦敦地区的形状文件。我用readShapePoly
函数从maptools
包将其加载到 R 中作为SpatialPolygonDataFrame
.
我想绘制这些多边形..我已经通过使用基本功能完成了plot
R 中的函数
输出如下图所示:
Now, I am trying to plot the same shape file using ggplot2
but it doesn't work for me.
I am getting some weird lines in the graph as shown below:
我使用的代码是:
london.wards <- readShapePoly("~/TD/london_wards2013/london_wards2013.shp"
, proj4string=CRS(projString))
wards.count <- nrow(london.wards@data)
# assign id for each lsoa
london.wards@data$id <- 1:wards.count
wards.fort <- fortify(london.wards, region='id')
ggplot(wards.fort, aes(long, lat)) + geom_polygon(colour='black', fill='white')
其中 projString 是描述用于输入形状文件的投影的投影字符串。
你需要添加额外的美感,group
。假设多边形 id 被称为ID
,语法将如下所示:
ggplot(wards.fort, aes(x = long, y = lat, group = ID)) +
geom_polygon(colour='black', fill='white')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)