要使用 rworldmap 绘制多个地图,您可以使用布局和几个循环来使用下面的代码创建这样的图。
我知道这些天循环并不酷,但我仍然这么认为。可能可以将所有这些放入应用类型函数中,但在绘图时循环的速度很少成为问题。
(另见 FAQ http://cran.r-project.org/web/packages/rworldmap/vignettes/rworldmapFAQ.pdf中的第 19 项多面板图
)
library(rworldmap)
newmap <- getMap(resolution = "coarse") #'low' or even 'coarse' resolution map may be sufficient
#example data for 2 years 6 months each
month <- c(1:6,1:6)
year <- c(rep(2012,6),rep(2013,6))
lon <- c(120:131)
lat <- c(-35:-24)
p1 <- data.frame(month=month,year=year,lon=lon,lat=lat)
months <- unique(p1$month)
years <- unique(p1$year)
oldPar <- par(mar=c(2, 0, 0, 2)) #margins top,bottom,left,right
#use layout to create multiple panels including space at top for a title
nPanels <- layout( cbind(c(0,1:6),c(0,7:12))
, heights=c(lcm(1),rep(1,6))
, respect=F )
for( yrNum in 1:length(years) )
{
yr <- years[yrNum]
for( moNum in 1:length(months) )
{
mo <- months[moNum]
cat(yr,mo,"\n")
plot(newmap, xlim = c(110, 155), ylim = c(-35, -20), asp = 1)
mtext( paste(yr,"month",mo), cex=0.7) #add titile to subplot
pMoYr <- p1[ p1$year==yr & p1$month==mo, ]
points(pMoYr$lon, pMoYr$lat, col = "red", cex = 3)
}
}
mtext("rworldmap layout demo",outer=TRUE,line=-2)
par(oldPar)