使用ggplot2和ggalt包绘制世界地图面板

James Austin(@awhstin)制作了基于R图形的4幅面板图,不过他没有用ggplot2来做。他说道:

ggplot2目前还不支持世界地图。从这点来说,它没有给我们一个很好的全球视角

最新的ggplot2 2.0.0版本已经支持世界地图。下面我们就利用ggplot2内置的面选项来绘制这4幅面板图。数据文件(CLIWOC15.csv)从这里下载。

注:本文还要用到的R包是ggalt。它是在ggplot2的基础之上扩展了一些新的geomscoordsstats特性。详情请见ggalt

library(ggplot2)  #需安装最新的2.0.0版本
library(dplyr)  #你也可以用内置的subset函数来代替filter函数
library(ggalt) #安装方法: devtools:install_github("hrbrmstr/ggalt")。需安装加载devtools包
library(ggthemes)

world <- map_data("world")
world <- world[world$region != "Antarctica",] # 剔除南极洲

dat <- read.csv("CLIWOC15.csv")        
dat <- filter(dat, Nation != "Sweden") 
 
gg <- ggplot()
gg <- gg + geom_map(data=world, map=world,
                    aes(x=long, y=lat, map_id=region),
                    color="white", fill="#7f7f7f", size=0.05, alpha=1/4)
gg <- gg + geom_point(data=dat, 
                      aes(x=Lon3, y=Lat3, color=Nation), 
                      size=0.15, alpha=1/100)
gg <- gg + scale_color_tableau()
gg <- gg + coord_proj("+proj=wintri")
gg <- gg + facet_wrap(~Nation)
gg <- gg + theme_map()
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme(legend.position="none")
gg

本文由雪晴数据网负责翻译整理,原文请参考World Map Panel Plots with ggplot2 2.0 & ggalt作者hrbrmstr。转载请注明原文链接http://www.xueqing.cc/cms/article/95


你可能感兴趣的:(filter,library,world,制作,世界地图)