sac*_*cvf 5 dictionary r netcdf ggplot2
我有一个netcdf文件,我想只是想象土壤深度图
[1] "file C:\\Users\\SoilDepth-gswp.nc has 3 dimensions:"
[1] "x Size: 360"
[1] "y Size: 150"
[1] "land Size: 15238"
[1] "------------------------"
[1] "file C:\\SoilDepth-gswp.nc has 3 variables:"
[1] "float nav_lon[x,y] Longname:Longitude Missval:1e+30"
[1] "float nav_lat[x,y] Longname:Latitude Missval:1e+30"
[1] "float SoilDepth[land] Longname:Soil depth Missval:1.00000002004088e+20"
Run Code Online (Sandbox Code Playgroud)
似乎我必须将纬度与经度以及地面点连接起来以获得土壤深度的地图.我真的很困惑.任何人都可以帮助我处理这类数据.
Pau*_*tra 11
我更喜欢使用ggplot2包进行可视化.使用@plannapus的优秀解决方案:
require(reshape)
require(ggplot2); theme_set(theme_bw())
land_df = melt(land)
ggplot(aes(x = X1, y = X2, fill = value), data = land_df) +
geom_raster() + coord_equal() +
scale_fill_continuous(na.value = "transparent")
Run Code Online (Sandbox Code Playgroud)

如果要更改轴的标题,请不要更改变量名称aes.这些值是指列中的数据,并改变它们导致你得到的错误,没有轴命名X的land_df.如果要更改轴上的名称:
ggplot(aes(x = X1, y = X2, fill = value), data = land_df) +
geom_raster() + coord_equal() +
scale_fill_continuous(na.value = "transparent") +
scale_x_continuous("X")
Run Code Online (Sandbox Code Playgroud)
pla*_*pus 10
library(ncdf)
# I'm assuming this is the netcdf file you are working with:
download.file("http://dods.ipsl.jussieu.fr/gswp/Fixed/SoilDepth.nc", destfile="SoilDepth.nc")
soil <- open.ncdf("SoilDepth.nc")
#The way to extract a variable is as following:
soil$var[[3]] -> var3 # here, as shown in your question, SoilDepth is the 3rd variable
get.var.ncdf(soil, var3) -> SoilDepth
dim(SoilDepth)
[1] 15238
Run Code Online (Sandbox Code Playgroud)
正如您在netcdf文件的摘要中所说的那样,变量仅SoilDepth取决于维度land而不取决于x,y因此我不确定在绘制此数据集时会给您留下什么.
编辑
事实证明,有一个键链接x,y并land:
download.file("http://dods.ipsl.jussieu.fr/gswp/Fixed/landmask_gswp.nc", destfile="landmask.nc")
landmask <- open.ncdf("landmask.nc")
landmask$var[[3]] -> varland
get.var.ncdf(landmask, varland) -> land
sum(land==1)
[1] 15238
Run Code Online (Sandbox Code Playgroud)
所以为了绘图:
# The values where stored in an expected order, hence the transpose
land = t(land)
land[land==1] <- SoilDepth
land[land==0] <- NA
land = t(land)
image(land)
Run Code Online (Sandbox Code Playgroud)
