r - 如何从 netcdf 文件中可视化 map ?

标签 r dictionary ggplot2 netcdf

我有一个 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"

看来我必须将纬度与经度以及陆地点连接起来才能获得土壤深度的 map 。我真的很困惑。任何人都可以帮助我处理此类数据吗?

最佳答案

我更喜欢使用 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")

enter image description here

<小时/>

如果您想更改轴的标题,请不要更改 aes 中的变量名称。这些值引用数据中的列,更改它们会导致出现错误,land_df 中没有名为 X 的轴。如果您想更改轴上的名称:

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")

关于r - 如何从 netcdf 文件中可视化 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12285120/

相关文章:

python - 创建嵌套字典的副本而不是引用

r - 将调色板分配给ggplot2中的元素

r - 每个 x 轴刻度具有不同因子顺序的条形图

r - 用 R 构造约束矩阵

python - 替换字典中的键

r - 当估计包含在函数中时,为什么更新方法不起作用?

python - 1.10 中关于 django.shortcuts.render() 方法签名的困惑

r - 可以在R中绘制图表吗?

css - Shinydashboard 选项卡高度

r - 如何获得每列的平均值,按某组分组?