我想用ggplot2创建一些地图,但我很难找到最好的方法。由于我有一个带矩阵的列表(“模型”),我想使用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&lt; - ggplot() map&lt; - map + coord_fixed() map&lt; - map + geom_polygon(data = map_data(map =“world”),aes(x = long,y = lat,group = group),fill = NA,color =“black”,size = 0.01) map&lt; - map + coord_cartesian(xlim = range(md $ lon),ylim = range(md $ lat)) map&lt; - map + geom_tile(data = md,aes(x = lon,y = lat,fill = SI),alpha = I(0.7)) map&lt; - map + scale_fill_gradientn(colors = cols) map&lt; - map + facet_grid(model~Season) map&lt; - map + theme(legend.position =“none”)
第二个问题是我不知道如何用白色改变背景,并使地图更加明显......这可能吗?问题是,我想绘制11行4列。因此,当一起绘制时,它看起来不太好......任何建议?
非常感谢任何帮助。
非常感谢