[R]: (Lattice): Overlaying more than one trend surface using contourplot() and wireframe()
Peter Ho
peter at fe.up.pt
Fri Aug 6 17:47:50 CEST 2004
Hi,
Is there a way to plot more than one trend surface using the functions
contourplot() and wireframe(). I have found an add=T in contour(), but
no equivalent argument in contourplot() and wireframe()?
I have taken the example 11-2 (pages 441-451) from Design and analysis
of experiments (Montgomery 2001, 5th edition) to see if this could be
done in R. I have managed to plot individual contours for each response
after using the surf.ls() and trmat() functions from the Spatial
package, but have been unable to overlay the contours. Ideally, it
would be nice to also choose a different set of colours for shading the
surface, so that when combing surfaces, we can immediately identify the
optimum conditions. The final overlaid plot is shown on page 451 (Figure
11-16) of the book.
Are there alternatve ways to also do this using other pakages ?
The R scipts for this examples can be found at the end of this email.
Thanks
Peter
..........................
################################################################################
g<- c(80,80,90,90,85,85,85,85,85,92.07,77.93,85,85)
h<- c(170,180,170,180,175,175,175,175,175,175,175,182.07,167.93)
Yield <- c(76.5,77.0,78.0,79.5,79.9,80.3,80.0,79.7,79.8,78.4,75.6,78.5,77.0)
viscosity <- c(62,60,66,59,72,69,68,70,71,68,71,58,57)
molwt <-
c(2940,3470,3680,3890,3480,3200,3410,3290,3500,3360,3020,3630,3150)
###################################################################################
## Fit 2-order Polynomial trend for Yield
Yield.ls <- surf.ls(2, g, h, Yield)
trsurfY<- trmat(Yield.ls,min(g), max(g),min(h), max(h),100)
trsurfY[c("x","y")]<- expand.grid(x=trsurfY$x,y=trsurfY$y)
## Fit 2-order Polynomial trend for viscosity
viscosity.ls <- surf.ls(2, g, h, viscosity)
trsurfV<- trmat(viscosity.ls,min(g), max(g),min(h), max(h),100)
trsurfV[c("x","y")]<- expand.grid(x=trsurfV$x,y=trsurfV$y)
## Fit 1-order Polynomial trend for molecular weight
molwt.ls <- surf.ls(1, g, h, molwt)
trsurfMW<- trmat(molwt.ls,min(g), max(g),min(h), max(h),100)
trsurfMW[c("x","y")]<- expand.grid(x=trsurfMW$x,y=trsurfMW$y)
####################################################################################
### Contourplot for yield
contourplot(z ~ x*y, data = trsurfY,
cuts = 10, region = TRUE,
xlab = "Time",
ylab = "Temperature",
main = "yield",
col.regions = trellis.par.get("regions")$col)
### Contourplot for viscosity
contourplot(z ~ x*y, data = trsurfV,
cuts = 10, region = F,
xlab = "Time",
ylab = "Temperature",
main = "yield",
col.regions = trellis.par.get("regions")$col)
### Contourplot for molecular weight
contourplot(z ~ x*y, data = trsurfMW,
cuts = 10, region = TRUE,
xlab = "Time",
ylab = "Temperature",
main = "yield",
col.regions = trellis.par.get("regions")$col)
##################################################################################
More information about the R-help
mailing list