使用光栅包绘制 netcdf 文件会导致表示失真,R

Plotting netcdf file with raster package leads to distorted representation, R

我想正确绘制这个 netcdf 文件:http://www.filedropper.com/sshgridsv16092015060412nc (Downloaded originally from here: https://opendap.jpl.nasa.gov/opendap/allData/merged_alt/L4/cdr_grid/contents.html)

但是 运行 遇到问题:

我应该能够绘制栅格(SLA 变量):

library(RNetCDF)
library(raster)
library(maptools)

d <- raster("ssh_grids_v1609_2015060412.nc.nc4", varname = "SLA")

plot(d)
#plot SLA

但是结果非常奇怪,正如您在提供的文件中看到的那样。

尤其是在顶部绘制世界地图时:

data(wrld_simpl)
plot(wrld_simpl, add = T) 

他们根本不匹配:/

所以我认为问题可能出在经度上(范围从 4.839944e-09 到 360)

然后我读到 raster::rotate(d)

应该是完美的(将经度调整到 -180 到 180),但它不允许我这样做。我收到此警告消息:

Warning message:
In .local(x, ...) :
  this does not look like an appropriate object for this function

plot(d) 

看起来还是一样。

如有任何建议,我们将不胜感激!

干杯

Netcdf 文件不仅经度 "rotated" 而且 x 和 y 的位置也不对。 netcdf中的输入方式显然不一般
我直接在 the OpenDap server 上下载了 netcdf,因为你的 filedropper link 似乎已损坏。
不管怎样,这是我的提议:

library(raster)
library(maptools)

d <- raster("ssh_grids_v1609_2015060412.nc.nc4", varname = "SLA")

# transpose x to y and double flip the map
m.r <- flip(flip(t(d), direction = "y"), direction = "x")

# then rotate from 0:360 to -180:180
rm.r <- rotate(m.r)

data(wrld_simpl)

plot(rm.r)
plot(wrld_simpl, add = T)