我根据netcdf文件和世界形状文件使用ggplo2绘制温度分布
但是我无法掩盖海洋区域,我想要的是一幅仅在陆地上着色并保持海洋区域蓝色的图片,geom_polygon只能填充陆地区域如何进行相反的填充?
THX
这是原始代码;
library(RNetCDF)
library(ggplot2)
library(maptools)
library(rgdal)
library(sp)
setwd("F:\\Programing\\Rnetcdf")
f<-open.nc("Soong.nc")
basemap<-readShapeSpatial("world.shp")
head(basemap)
shore <- fortify(basemap)
#shore$long<-shore$long+180
head(shore)
var.inq.nc(f,"TMP_P0_L109_GLL0")
apt<-var.get.nc(f,"APTMP_P0_L103_GLL0")
lon<-var.get.nc(f,"lon_0")
lat<-var.get.nc(f,"lat_0")
newlon<-rep(lon,each=length(lat))
newlat<-rep(lat,length(lon))
newapt<-as.vector(t(apt))
newlon[newlon>180]<-newlon[newlon>180]-360
draw<-as.data.frame(cbind(newlat,newlon,newapt))
finaldraw<-ggplot(data=draw,aes(x=newlon,y=newlat,fill=newapt))+
geom_raster(interpolate=F)+
scale_fill_gradientn(colours = rev(rainbow(7)), na.value = NA) +
geom_polygon(data = shore, aes(x=long, y = lat, group = group), color = "black",fill=NA) +
theme_bw()
这是上面代码的图片