[R] levelplot and unequal cell sizes

Waichler, Scott R Scott.Waichler at pnl.gov
Wed Apr 25 22:55:17 CEST 2007

Hadley and Deepayan,

Thank you for responding.  Here is a simple example of what I'm talking
about.  It is a grid that is 5 cells wide by 2 cells tall.  The width of
the cells in the x-direction is variable; the cells at either end have
width = 4 units, and the three cells in the middle have width = 2 units.
My objective is to have the color contour boundaries fall on the cell
boundaries instead of equidistant between cell nodes.  In the plot, I
want the cyan/blue and orange/gray boundaries to be located at the red
cell boundary lines.  Also, the colored regions should extend to the
ends of the domain (x = 0, 14).


x.node <- rep(c(2, 5, 7, 9, 12), 2)
y.node <- c(rep(0.5, 5), rep(1.5, 5))
z <- rep(1:5, 2)
contour.levels <- seq(0.5, 5.5, by=1)
x.cell.boundary <- c(0, 4, 6, 8, 10, 14)
contour.colors <- c("cyan", "blue", "green", "orange", "gray")
  levelplot(z ~ x.node * y.node,
     panel = function(z,...) {
        panel.abline(v = x.cell.boundary, col="red")
     xlim = range(x.cell.boundary),
     colorkey = list(space="top", width=1, height=0.9,
                     labels=list(labels=z, at=z)
     region = T,
     contour = F

Any help you can offer is appreciated.

Scott Waichler
Pacific Northwest National Laboratory
scott.waichler _at_ pnl.gov

More information about the R-help mailing list