我必须使用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轻松绘图,并以通常的方式添加地图。
例如,rasterVis
和ggplot2
应该像这样工作:
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()