SpatialPolygonDataFrame使用ggplot进行绘图 [英] SpatialPolygonDataFrame plotting using ggplot
问题描述
maptools
包中的 readShapePoly
函数将它作为 SpatialPolygonDataFrame
。 我想要绘制这些多边形。我已经通过使用 现在,我正在使用 我使用的代码是: 其中projString是描述用于输入形状文件的投影的投影字符串。 您需要添加额外的审美元素, I am having a shape file for the greater London area. I use the I want to the plot those polygons .. Which I have already done by using the basic of Now, I am trying to plot the same shape file using The code I used was : where projString is the projection string describing the projection used for the input shape file. You need to add an additional aesthetic,
这篇关于SpatialPolygonDataFrame使用ggplot进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! plot
中的函数
输出如图所示:
绘制相同的形状文件, ggplot2
但它不适用于我。
我得到了一些古怪的线条,如图所示:
london.wards< ; - readShapePoly(〜/ TD / london_wards2013 / london_wards2013.shp
,proj4string = CRS(projString))
wards.count< - nrow(london.wards@data)
#为每个lsoa分配id
london.wards@data$id< - 1:wards.count
wards.fort< - fortify(london.wards,region ='id')
ggplot(wards.fort,aes(long,lat))+ geom_polygon(color ='black',fill ='white')
group
。假设多边形ID称为 ID
,则synatx将如下所示:
ggplot(wards.fort,aes(x = long,y = lat,group = ID))+
geom_polygon(color ='black',fill ='white')
readShapePoly
function from the maptools
package to load it in R as a SpatialPolygonDataFrame
.plot
function in R.
The output looks as shown in this image:ggplot2
but it doesn't work with me.
I am getting some weird lines in the graph as shown blew:
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')
group
. Assuming the polygon id is called ID
, the synatx will look like:ggplot(wards.fort, aes(x = long, y = lat, group = ID)) +
geom_polygon(colour='black', fill='white')