[R] 4D Plot ??

From: Mike Prager <Mike.Prager_at_noaa.gov>
Date: Thu 07 Apr 2005 - 23:47:29 EST


Tried to post this last night, but it doesn't seem to have appeared.

Using R 2.0.1 on Windows XP + SP2.

I am traveling, away from my usual references. I'm trying to make a 4-dimensional plot: a levelplot with overlaid contours, with different response variables represented by (1) colors on the levelplot and (2) the contour lines.

First try was filled.contour + contour but the key printed by the first means that the scales differ.

Then I tried levelplot. I couldn't figure out how to pass > 3 variables to levelplot, so I duplicated all rows of the data frame and changed the z data for the second half, in order to plot one half at a time.

#----------------------------------------------------------
# Try at a 4D contourplot:
y = x = 1:50
grid <- expand.grid(x=x, y=y)
grid$z = sqrt(x*y)
n1 = nrow(grid)
grid2 = rbind(grid,grid)
grid2$z[(n1+1):(n1*2)] = log(grid2$x[1:n1] * grid2$y[1:n1] + 10) panel.4d <- function(x,y,z,subscripts) {

   n1 = 1; n2 = length(x)/2
   panel.levelplot(x[n1:n2],y[n1:n2],z[n1:n2],subscripts,region=TRUE)    n1 = n2 + 1 ; n2 = length(x)   

panel.levelplot(x[n1:n2],y[n1:n2],z[n1:n2],subscripts,region=FALSE,contour=TRUE)

   }
aa = levelplot(z~x*y, data=grid2, cuts = 20, panel=panel.4d) print(aa)

#------------------------------------------------------------

This gives the following error message:

Error in panel.levelplot(x[n1:n2], y[n1:n2], z[n1:n2], subscripts, region = FALSE, :

        NAs are not allowed in subscripted assignments  

although that it completes when the second levelplot is set to region=TRUE, contour=FALSE (though then the second plot then hides the first).

Hints or sample code will be most welcome. Once this works, the next refinement will be to replace the colored levelplot with something similar but with smooth edges produced by contouring, so advice on that is also welcome.

Michael Prager, Ph.D.
NOAA Center for Coastal Fisheries & Habitat Research Beaufort, North Carolina, USA



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Apr 07 23:56:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:03 EST