使用 r 包在地图上绘制轮廓 netcdf 变量的简单方法

Simple way to contour netcdf variables on a map using r package

我必须使用 R 包绘制地图,以便绘制国家限制,以及从 NetCDF 文件读取的气象变量值的等高线。

我执行以下操作:

r=raster('netcdffile.nc')
map('worldHires', xlim=c(-10,50), ylim =c(30,50))
plot(r, add = TRUE)
contour(r, add = TRUE)

但未显示国家/地区限制。 栅格的绘制似乎消除了先前绘制的国家/地区限制。 我需要一个简单的方法。

附加一个具有正确坐标的示例 netcdf 文件会有所帮助。我手头没有任何 netCDF 文件可以测试。您是否尝试过优秀的 rasterVis 套餐?您可以使用 trellis 或 ggplot 轻松绘制,并以通常的方式添加地图。

例如 rasterVisggplot2 这样的事情应该有效:

r=raster('netcdffile.nc')
library(rasterVis)
library(maps)
world <- data.frame(map(plot=FALSE)[c("x","y")])
gplot(r) + 
  geom_tile(aes(fill=value)) + 
  geom_path(data=world, aes(x,y)) +  
  stat_contour(aes(z=value)) +
  coord_equal()