Skip to content
Prev 22112 / 29559 Next

How do I read and plot .nc data in R?

I had sent a second email that did not make it to the archives it seems,
here it is:

I think it works fine, I downloaded your file and:

library(raster)
 f <- "yfin_20141219.nc"
r <- raster(f)
plot(r)
## check we get sensible orientation and scaling and offset and
interpretation etc. etc.
library(rworldmap)
data(countriesLow)
plot(countriesLow, add = TRUE)

r
       : RasterLayer
dimensions  : 541, 649, 351109  (nrow, ncol, ncell)
resolution  : 0.08333333, 0.08333333  (x, y)
extent      : 89.95833, 144.0417, -20.04167, 25.04167  (xmin, xmax, ymin,
ymax)
coord. ref. : +proj=longlat +datum=WGS84
data source : C:\Users\mdsumner\Downloads\yfin_20141219.nc
names       : yft_adu
z-value     : 251164800
zvar        : yft_adu

Note that in general, reading a raw array from file and applying this
assumptive georeferencing is fraught with danger:
?
y <- raster(data.adl, xmn=-20, xmx=25, ymn=90, ymx=144)

You should check assumptions about the orientation, order, units and
scaling of the coordinate arrays. The raster package is pretty smart about
telling you when danger lurks, but I would still be very careful.  NetCDF
doesn't generally get used store the standard GIS affine transform, it
usually stores every dimension's coordinate and only removes that
redundancy in some cases for rectilinear grids. It's one of those murky
boundaries between different worlds.

HTH

Cheers, Mike.
On Fri Dec 19 2014 at 20:33:20 Eko Susilo <ekosusilo at live.com> wrote: