R语言学习笔记:绘制地图

在R中画地图先从简单的maps包开始。

library("maps")

在这个maps包中有一些数据集,用命令data(package=”maps”),可以看到如下数据:

canada.cities          Database of Canadian cities
county.fips            FIPS county codes for US County Map
countyMapEnv           United States County Map
franceMapEnv           France Map
italyMapEnv            Italy Map
nzMapEnv               New Zealand Basic Map
ozone                  Sample datasets
state.carto.center     United States State Population Cartogram Map
state.cartoMapEnv      United States State Population Cartogram Map
state.fips             FIPS state codes for US 48 State Map
state.vbm.center       United States State Visibility Base Map
state.vbmMapEnv        United States State Visibility Base Map
stateMapEnv            United States State Boundaries Map
unemp                  Sample datasets
us.cities              Database of US cities
usaMapEnv              United States Coast Map
votes.repub            Sample datasets
world.cities           Database of world cities
world2MapEnv           Pacific Centric Low resolution World Map
worldMapEnv            Low resolution World Map

 

画出美国各州的边界:

map('state', panel.first=grid())

axis(1,lwd=0)

axis(2,lwd=0)

axis(3,lwd=0)

axis(4,lwd=0)

box()

image

标出美国的城市:

data(us.cities)

points(us.cities$long, us.cities$lat, pch=19)

image

标出人口大于一百万的城市

cities <- us.cities[us.cities$pop > 1000000,]

points(cities$long, cities$lat, pch=19)

text(cities$long, cities$lat, cities$name, col="blue", cex=0.8, pos=1)

image

 
强大的ggmap中的get_map()可以方便获得各种地理或遥感图像数据,可惜现在的google被屏蔽,试不了了。
下面这个是用VPN后调用get_map取得的美国地图图像。
 
另外也可以用OpenStreetMap包。
library("OpenStreetMap")
map <- openmap(c(50,-130), c(20,-60),type="apple-iphoto")
plot(map)
 
 
posted @ 2014-11-14 13:58  申龙斌的程序人生  阅读(11227)  评论(0编辑  收藏  举报