I want to make a hovmoller diagram; I want to change the order of Y axis (to start with 2010 - on bottom and finish 1970 - to be on top:


              destfile = 'SST.nc') # here you can find the data (about 3,9 MO size)

SST <- brick('data.nc')
idx <- seq(as.Date('1970-01-01'), as.Date('2003-03-01'), by='month')
tt <- as.yearmon(idx)
SST <- setZ(SST, tt)
names(SST) <- as.character(tt)

          panel = panel.levelplot.raster,
          interpolate = TRUE,
          yscale.components = yscale.raster.subticks,
          par.settings = BuRdTheme)

So I need to have 1970 on top of the graph instead of 2010. Anyone can offer some help please?

  • you download the file as SST.nc but read in data.nc - edit?
    – Spacedman
    Commented Nov 27, 2018 at 12:29
  • It looks like if the Z values are numeric or "yearmon" then it will always plot sorted numerically that way. If you set the Z values to character then its plotted in the order of the layers, but in this case the X axis gets 399 overlapping unreadable labels...
    – Spacedman
    Commented Nov 27, 2018 at 12:55
  • @Spacedman - yes, I downloaded the wrong file (I copied the example from rasterVis help page). sorry for this Commented Nov 27, 2018 at 14:13

1 Answer 1


Let's try this. First reverse the order of layers in SST into SSTR:

> SSTR = SST[[nlayers(SST):1]]

Then set the Z for SSTR as the reverse of SST, and convert to character so that hovmoller doesn't go and sort it back again for us:

> SSTR= setZ(SSTR, rev(as.character(getZ(SST))))

Next plot but only label the Y axis every two years, starting from the first January:

> hovmoller(SSTR, scales=list(y=list(at=seq(3, nlayers(SSTR),by=24))))

enter image description here

Please check carefully that this is all right before using it in anger. It looks different to hovmoller(SST) but there may be a bunch of other reasons for that! I have tried some tests on tiny raster stacks so I'm fairly confident...

  • Many thanks, great idea! Is working with my data so I am pretty sure that your suggestion is good. Commented Nov 27, 2018 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.