在国家层面绘制地图有很多解决方案,但就我而言,我想在大陆层面打印统计数据.
我想到的唯一事情是使用国家级地图并使用每个大洲的国家列表,但我想知道这种地图是否有任何简单的解决方案.为了实现我的想法,它将是这样的:
## produce the world map
map()
## list of countries per continent
SA <- c("argentina", "bolivia", "brazil", "chile", "colombia", "ecuador", "guyana", "paraguay", "peru", "suriname", "uruguay", "venezuela")
map(regions = SA, fill=TRUE, add=TRUE)
Run Code Online (Sandbox Code Playgroud)
And*_*ndy 14
rworldmap
具有绘制或汇总数据到包括大陆在内的区域级别的功能.
一个简单的开始应该产生如下图:
library(rworldmap)
#get coarse resolution world from rworldmap
sPDF <- getMap()
#mapCountries using the 'continent' attribute
mapCountryData(sPDF, nameColumnToPlot='continent')
Run Code Online (Sandbox Code Playgroud)
或者对于7大洲模型:
mapCountryData(sPDF, nameColumnToPlot='REGION')
Run Code Online (Sandbox Code Playgroud)
要将您自己的数据从国家/地区汇总到区域级别,请查看:
?mapByRegion
Run Code Online (Sandbox Code Playgroud)
跟随@Andy的回答,您可以合并每个大陆中的国家多边形,如下所示:
library(rworldmap)
library(rgeos)
library(maptools)
library(cleangeo) ## For clgeo_Clean()
sPDF <- getMap()
sPDF <- clgeo_Clean(sPDF) ## Needed to fix up some non-closed polygons
cont <-
sapply(levels(sPDF$continent),
FUN = function(i) {
## Merge polygons within a continent
poly <- gUnionCascaded(subset(sPDF, continent==i))
## Give each polygon a unique ID
poly <- spChFIDs(poly, i)
## Make SPDF from SpatialPolygons object
SpatialPolygonsDataFrame(poly,
data.frame(continent=i, row.names=i))
},
USE.NAMES=TRUE)
## Bind the 6 continent-level SPDFs into a single SPDF
cont <- Reduce(spRbind, cont)
## Plot to check that it worked
plot(cont, col=heat.colors(nrow(cont)))
## Check that it worked by looking at the SPDF's data.frame
## (to which you can add attributes you really want to plot on)
data.frame(cont)
# continent
# Africa Africa
# Antarctica Antarctica
# Australia Australia
# Eurasia Eurasia
# North America North America
# South America South America
Run Code Online (Sandbox Code Playgroud)
library(sp) #Load your libraries
library(maptools)
#Download the continents shapefile
download.file("http://baruch.cuny.edu/geoportal/data/esri/world/continent.zip",
"cont.zip")
#Unzip it
unzip("cont.zip")
#Load it
cont <- readShapeSpatial("continent.shp")
#Plot it
plot(cont,
col=c("white","black","grey50","red","blue","orange","green","yellow"))
#Or any other combination of 8 colors
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10291 次 |
最近记录: |