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
On Thu, 7 Apr 2005, Mike Prager wrote:> 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.You could put the contour() call in the plot.axes argument in the filled.contour() call. This is a useful trick for getting the right scales for an overlay. -thomas
Hi Mike, I've done a bit of playing around with these kind of plots for visualising microarray data (to eventually go into a bioconductor package). I've attached my code for producing surfaceplots (my name for the type of plots that includes both image and contour plots) - it's all lattice based, so you'll need some familiarity with how lattice works to understand how it all works. The key function is panel.superpose.surface which you can use as follows: levelplot(surfacevar + contourvar ~ x * y, data, panel=panel.surface.smooth, asp="iso") (note that the contours are automatically smoothed using image.smooth from the fields package - you can control the amount of smoothing use contour.theta) You can supply multiple contour variables, but be advised it gets messy really quickly! You can also smooth the surface by setting panel.base = panel.surface.smooth Hope this is helpful! Hadley -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: surfaceplot-ma.R Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050407/a6a230f1/surfaceplot-ma.pl
Hi,Thomas: We meet a problem of plotting 3d, which is a part of 5D. In other word, we just fixed the rest of 2 variables and slice 5d into 3d. Consider a function like Y=f(x1, x2, x3, x4). We want to have a 3D surface plot in R for the fitted value Yhat (which is of course a function of x1, x2, x3 and x4) against x1 and x2 say, keeping x3 at its median level and fixing x4 as =1 (note that x4 is binary which can take values of 1 or 0 only). So we plot yhat, x1 and x2 in 3D surface after estimating the whole model (based on all 4 covariates) . How do we do that? Please advice. If you feel it is more involved then Kun can come to your office/consulting center for help. Awaiting your reply. Thanks for your time, Best Kun [[alternative HTML version deleted]]