用R中的级别绘制netcdf文件 [英] Plotting netcdf file with levels in R
问题描述
我最近开始在R中使用netcdf.示例数据在这里:
I have recently started to work with netcdf in R. Sample data is here:
http://www.earthstat.org/data-download/>已收获175种作物的作物面积和单产>单季作物>大豆_HarvAreaYield2000_NetCDF
http://www.earthstat.org/data-download/ > Harvested area and yield for 175 crops > individual crops > soybean_HarvAreaYield2000_NetCDF
在此文件夹中,有一个名为soybean_AreaYieldProduction.nc
In this folder, there is a netcdf file called soybean_AreaYieldProduction.nc
这是我打开netcdf的方式
This is how I open the netcdf
library(ncdf4)
dat <- nc_open("soybean_AreaYieldProduction.nc")
print(soy)
1 variables (excluding dimension variables):
float soybeanData[longitude,latitude,level,time]
LayerDescriptions: struct(5).Data(:,:,1/2/3/4/5/6) to access data layer: 1=Harvested Area fraction, 2=Yield 3=Harvested Area data quality, 4=Yield data quality, 5=Harvested Area in hectares, 6= Production
Units: Harvested Area Fraction(1)=percent of gridcell that was harvested, Yield(2)=metric tons per hectare, Harvested Area Hectares(5)=total hectares harvested per gridcell, Production(6)=Metric Tons
DataQuality: In levels 3 and 4, a value of 1 = county; .75 = state; .5 = interpolated from within 2 degrees lat/long; .25 = country; 0 = missing.
4 dimensions:
longitude Size:4320
units: longitude
latitude Size:2160
units: latitude
level Size:6
time Size:1
我想绘制每个级别,但不知道如何为每个级别提取数据.
I want to plot each level but do not know how to extract data for each level.
这是我提取lon和lat数据的方式:
This is how I extract lon and lat data:
lon <- ncvar_get(dat,"longitude") # extract long
lat <- ncvar_get(dat,"latitude") # extract lat
但是我如何提取单个水平?
But how do I extract individual levels?
level.1 <- ncvar_get(dat, ????)
最终目的是可视化每个级别 我想使用以下命令进行可视化:
Ultimate aim is to visualize each levels I want to visualize using the following command:
image(lon,lat, level)
推荐答案
使用raster
包可能最简单:
library(raster)
r1 <- raster("soybean_AreaYieldProduction.nc", level=1)
r2 <- raster("soybean_AreaYieldProduction.nc", level=2)
plot(r1)
image(r1)
s <- stack(r1, r2)
plot(s)
其他绘图方法
spplot(s)
library(rasterVis)
levelplot(r1)
levelplot(s)
并在CRAN上查看其他映射包
And see other mapping packages on CRAN
这篇关于用R中的级别绘制netcdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!