Search code examples
rrasterlatticer-rasterrastervis

Change the zone interval in rasterVis horizonplot


I'm working with rasterVis horizonplot function and I want to change the zone interval; for example I want to show the average for every 10 latitudinal zones in the x axis. This is an example from rasterVis library.

library(raster)
library(rasterVis)
horizonplot(SSTanom, col.regions = rev(brewer.pal(n = 10, 'RdBu')))

Solution

  • The zones are determined by the zonal function, that is indirectly accesible via the digits argument (integer, number of digits to maintain). With this approach you don't have full control of the number of intervals. For example:

    horizonplot(SSTanom, digits = -1)
    

    horizonplot and digits

    Another solution is the dirXY argument of horizonplot which gives more flexibility. For example:

    horizonplot(SSTanom, dirXY = cut(y, 10))
    

    horizonplot and cut

    Unfortunately, cut does not preserve the label of the interval (because a Raster cannot store characters), so the name of each panel is not directly related to the zone.