4

我正在尝试使用此JSS 论文ProportionalSymbolMap中定义的地图。

为了绘制比例符号,我首先需要一个地图类的对象。

然而,我通常使用的方法返回 SpatialPolygonDataFrame。有什么包或方法可以在这里提供帮助吗?

4

1 回答 1

4

哈克是解决这个问题的方法。我只是使用这组命令将 SpatialPolygons* 对象拆开,然后将其重新组合为 class 的对象map。我希望你喜欢它:

# read in shapefile as normal SpatialPolygons
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))

# Formatting the data
require(reshape)
# Identifier column to split data on
xx@data$id <- rownames(xx@data)

# Convert to dataframe
xx.df <- as.data.frame(xx)

#Fortfy automagic
xx.fort <- fortify(xx, region="id")

# Join operation - one row per coordinate vector
xx <- join(xx.fort, xx.df,by="id")

# Split by ID because we need to add NA at end of each set of polygon coordinates to 'break' the line
xxSp <- split(xx, xx$id)

# Need to insert NA at end of each polygon shape to cut off that shape
xxL <- do.call( rbind , (lapply( xxSp , function(x) { j <- x[ nrow(x) , ] ; j[1:2] <- c(NA,NA); rbind( x , j ) })) )


# Create list object with same structure as map object
xxMap <- list( x = xxL$long , y = xxL$lat , range = c( range(xxL$long) , range(xxL$lat) ) , names = as.character(unique( xxL$NAME ) ) )

# Define as a map class object
attr(xxMap , "class") <- "map"

# Plot!!
map( xxMap )

在此处输入图像描述

于 2013-04-23T12:34:51.417 回答