[R] Countour for netCDF-like meshes

Julio Sergio Santana juliosergio at gmail.com
Mon Oct 28 16:01:05 CET 2013


Hi,
A model gives me as output a netCDF file which I read with ncdf package. The 
output consists of three similar matrices: one contains the variable value, 
and the other two, the longitude and latitude coordinates. I need to do a 
contour graph with such information, however, the R contour function 
expects, 
two vectors X, Y, and a matrix Z, as its input. X and Y, being the same 
length as the number of rows and columns of Z matrix, respectively. This 
implies that the Z values in the same row, all have the same abscissa, and 
the Z values in the same colum, all have the same ordinate.

I know, in systems  similar to matlab, ferret, ncl, and the like, you just 
give the three matrices, and the system performs all the necessary 
interpolations to display the contour. Do you know if there is a way to do 
the same in R?

Though not exactly an output in a netCDF, I'm presenting here a very 
simplified example of the kind of output I need to plot.

  val <- matrix(c(rep(15,5),rep(c(15:17,16,15),2),rep(15,5)),nrow=4,byrow=T)
  v1 <- 1:5
  v2 <- 10:13
  xx <- cbind(v2, v2+.1, v2+.2, v2+.1, v2)
  yy <- rbind(v1, v1+0.1, v1+0.2, v1+0.1)

val: is the matrix with the values I want to plot.
xx: is the corresponding abscissa values.
yy: is the corresponging ordinate values.


Thanks,

  -Sergio.



More information about the R-help mailing list