I am trying to plot this NetCDF file (and similar) as a 2d contour map.
The file contains a single layer of one variable, "pr".
The file has 413x229 X-Y pixel coordinates, and, stored inside the "xlon" and "xlat" variables, the exact coordinates of each grid point.
I can easily plot using X-Y coordinates:
filename <- "file.nc" varname <- "pr" library(raster) variable <- raster(filename, varname=varname) plot(variable)
Hpwever, the plot comes out "squeezed", and moreover I want to plot using lat-lon coordinates. How can I do that?
This is somehow similar, I think, to this question:
However, the solution given there is not suited to my case because:
- I would like to avoid using the
ncdf4package, I'd prefer to use
rasteronly as this would allow me to expand the procedure to bigger files
- I get several errors in the
convertGrid()function, such as:
Error in .subset(x, j) : only 0's may be mixed with negative subscripts
I should reverse the projection, I think. All I know of the projection is contained in the file ncdump:
projection = "LAMCON" grid_size_in_meters = 12000. latitude_of_projection_origin = 39. longitude_of_projection_origin = 14. standard_parallel = 35., 51. grid_factor = 0.684241343018562
The file does not have a CRS specification.
I know I should be able to do so using the
rasterVis packages but so far I've not succeeded.
Trying to plot as a data.frame does not work either because the grid is not constant.