1
votes

I am using R lattice() to make a 3D wireframe plot. The color scale for the surface ranges from -0.6 to +0.2. I created a blue-white-red color gradient scheme with:

bwr.colors <- colorRampPalette(c("blue, "white", "red"))

and am creating the plot like so:

gca_plot <- wireframe(dev ~ col*row, data=gca, 
           xlab = "col",
           xlim = c(1, 24),
           ylab = "row",
           ylim = c(9, -6),
           zlim=c(-0.6, 0.2),
           main = "GCA",
           drape = TRUE,
           colorkey = TRUE,
           at=do.breaks(c(-0.6,0.2),100),
           scales = list(arrows=FALSE,cex=.5, tick.number = 10, z = list(arrows=F), distance =c(1.5, 1.5, 1.5)),
           col.regions = bwr.colors(100),
           screen = list(z = 30, x = -60))

The problem is that I'd like to center color (white) to be at zero since this is a deviation plot. I want red values > 0 and blue < 0.

I know that making my scale run from -0.6 to +0.6 would solve this, but that uses up a much-too-small portion of the z-axis. I also know that the scale_colour_gradient2() function can achieve what I want (it allows you to set the midpoint value), but that's a ggplot2() function and I'm in lattice() since ggplot2() doesn't do 3-D surfaces like this (unless I missed something).

Here's what my plot looks like. It's crammed in the corner of the frame by design -- it's a 13x9 field that will be compared to a different plot containing a 24x16 field.

enter image description here

1

1 Answers

1
votes

Here is one approach:

library(lattice)

bwr.colors <- colorRampPalette(c("blue", "white", "red"))

some data for plotting:

g <- expand.grid(x = 1:10, y = 5:15)
g$z <- log(g$x^2 + g$y^2)

by controlling the values in the at argument, for instance:

c(do.breaks(c(3, 4),49), do.breaks(c(4, 6),49))

will create 100 values, of which the first 50 will be between 3 and 4 and the other 50 will be between 4 and 6

wireframe(z ~ x*y, data=g, 
          xlab = "col",
          ylab = "row",
          main = "GCA",
          drape = TRUE,
          colorkey = TRUE,
          at = c(do.breaks(c(3, 4),49), do.breaks(c(4, 6),49)),
          scales = list(arrows = FALSE,
                        cex = .5,
                        tick.number = 10,
                        z = list(arrows=F),
                        distance =c(1.5, 1.5, 1.5)),
          col.regions = bwr.colors(100),
          screen = list(z = 30, x = -60))

enter image description here

in your case you probably need:

c(do.breaks(c(-0.6, 0),49), do.breaks(c(0, 0.2),49))