我想用ggplot2创建一些 Map ,但我很难找到最好的方法 . 由于我有一个带矩阵的列表(“模型”),我想使用ggplot,因为那样,创建一个多时隙应该更容易(使用facet_wrap ...但只是一个想法) . 我将创建一个可重现的示例来执行此操作:
#European corrdinates
lon <- rep(loni,38) #longitude values -13W-34E
lat <- rep(lati, each = 48) #latitude values 34N-70N
#Matrix of values
mod <- matrix( rnorm(48*38,mean=0,sd=1), 48, 38)
#Create a list of matrix (as my real data)
dat.mod <- rep(list(mod), 4)
names(dat.mod) <- c("DJF","MAM","JJA","SON")
#Order data
md <- melt(dat.mod)
md$lon <- lon
md$lat <- lat
md$group <- "Model1"
names(md) <- c("X1","X2","SI","Season","lon","lat","model")
#
#First try:
#Problem here: I don't know how to add the map
brks <- seq(0, 2.2, by=0.2)
cols <- colorRampPalette(c("skyblue1", "lightcyan2", "lightyellow", "yellow", "orange", "red3"))(length(brks)-1)
m <- ggplot(data = md, aes(x = lon, y = lat, fill = SI)) +
geom_raster() +
scale_fill_gradientn(colours = cols, na.value = NA)+
facet_wrap(~ model~ Season, nrow =11,ncol=4)+
theme(strip.background = element_blank(),
strip.text.x = element_blank())
#I would get this image:
#Now,作为第二次尝试添加欧洲 Map ,我用过:map < - ggplot()map < - map coord_fixed()map < - map geom_polygon(data = map_data(map =“world”),aes(x = long,y = lat,group = group),fill = NA,color =“black”,size = 0.01)map < - map coord_cartesian(xlim = range(md $ lon),ylim = range(md $ lat)) map < - map geom_tile(data = md,aes(x = lon,y = lat,fill = SI),alpha = I(0.7))map < - map scale_fill_gradientn(colors = cols)map < - map facet_grid(model~季节) Map < - Map 主题(legend.position =“none”)
现在,我会:
第二个问题是我不知道如何用白色改变背景,并使 Map 更加明显......这可能吗?问题是,我想绘制11行4列 . 所以当一起绘图时看起来不太好......有什么建议吗?
真的很感激任何帮助 .
非常感谢