Error plotting data from netcdf file “increasing x y values expected”

I want to plot sea surface temperature data from a regular grid but can't find the proper way to do it. My data comes in nc format and can be downloaded from

I use this R code to access data but the problem appears when trying to plot

download.file("", destfile="")
x <- get.var.ncdf(data,"lon")
y <- get.var.ncdf(data,"lat")

filled.contour(x,y,sst, color = terrain.colors, asp = 1)

And then get this error message

Error en filled.contour(x, y, sst, color = terrain.colors, asp = 1) : increasing 'x' and 'y' values expected

I think the problem comes from y coordinate, latitude runs from 90 to -90. I've seen some questions on stackoverflow in creating a new grid with akima package but it should not be necessary in this case.

Here you can find a summary of data file

Thanks in advance for your help


Thanks to Paul Hiemstra

The point was not read lat-lon values from data set but to know the i,j coordinates of data points in the matrix and then select the geographic area I want to plot. Following are the commands that work for me:

download.file("", destfile="")
x = seq(1, 8640, length.out = nrow(sst))         # Matrix dimension 8640x4320
y = seq(1, 4320, length.out = ncol(sst))

sst1 <- sst[c(1000:1500),c(1000:1500)]           # Subsetting a region
x = seq(1, 500, length.out = nrow(sst1))
y = seq(1, 500, length.out = ncol(sst1))

filled.contour(x,y,sst1, color = terrain.colors, asp = 1)

Now I have to figure out how to label the plot with longtiude and latitude at x-y coordinates.


The problem is probably the following. Your x and y variables are of the same size of sst, i.e. they provide maps of x and y coordinates. What the filled_contour function needs is not these maps, but more simply the x and y coordinates associated with the rows and columns in sst with increasing x values.

Although my question was solved with the help of Paul Hiemstra I've still investigated on plotting my netcdf data and found another thread in Stackoverflow that has also helped me. It uses image instead of filled.contour.

You can find the thread at The variable from a netcdf file comes out flipped

Now, this is the code I am using to plot SST data:

download.file("", destfile="")


data$dim$lon$vals -> lon
data$dim$lat$vals -> lat
lat <- rev(lat)
sst <- sst[,ncol(sst):1]
image(lon, lat, sst, zlim=c(270,320), col = heat.colors(37))
library("sp", lib.loc="/usr/lib/R/site-library")
library("maptools", lib.loc="/usr/lib/R/site-library")
plot(wrld_simpl, add = TRUE)

that leads to this image:

Need Your Help

Writing Multithreaded Exception-Safe Code

c++ multithreading exception c++11

What are the tensions between multithreading and exception-safety in C++? Are there good guidelines to follow? Does a thread terminate because of an uncaught exception?

What good template language is supported in JavaScript?

javascript templates

Templates are a pretty healthy business in established programming languages, but are there any good ones that can be processed in JavaScript?