Greetings, R helpers,

I have been using the Tps() function in the fields package to model response 
surfaces for some dietary research in crickets.  Overall, I have *three* 
independent variables of interest, two continuous variables ("protein" and 
"carbohydrate") and one categorical variable (cricket "morph").  My overall 
goal is to produce two heat maps where colors are scaled on the same absolute 
scale.  As best I see it, there are two possible ways to achieve this: some 
adjustment to the image() function parameters, or some adjustment to the Tps() 
function and subsequent method to separate the two plots (this would also 
require rearrangement of the data frame).  

However, I am stumped on the particulars.  Does anyone have an idea of how to 
do this?  I am including (hopefully reproducible) syntax for the two separate 
surfaces below.

Thank you,
Rebecca Clark
Postdoctoral Research Associate
Texas A&M University


######

library(fields)

triact<-structure(list(Diet = structure(1:13, .Label = c("A", "B", "C", "D", 
"E", "F", "G", "H", "I", "J", "K", "L", "M"), class = "factor"), LW = c(19, 14, 
9, 19, 13, 6.8, 16.9, 2.4, 18.1, 3.5, 16, 8.3, 11), SW = c(5.5, 8.5, 11.7, 6, 
3.5, 4, 5.5, 3.2, 9.1, 3.1, 7.5, 3, 3.5), protein = c(18, 28, 8, 28.75, 4, 
17.25, 13, 14, 16.25, 9, 27, 9.75, 23), carbohydrate = c(24, 14, 34, 23.75, 17, 
14.25, 29, 7, 36.25, 12, 36, 21.75, 19)), .Names = c("Diet", "LW", "SW", 
"protein", "carbohydrate"), class = "data.frame", row.names = c(NA, -13L))

attach(triact)

surf.teLW=Tps(cbind(protein,carbohydrate),LW, lambda = 0.01)
surf.teSW=Tps(cbind(protein,carbohydrate),SW, lambda = 0.01)

# Method for separately producing the surface and then mapping contour lines 
onto it (instead of using "surface()"):
surf.te.outLW=predict.surface(surf.teLW)
surf.te.outSW=predict.surface(surf.teSW)

par(mfrow=c(1,2))

image(surf.te.outLW, col=tim.colors(128), lwd=5, las=1, font.lab=2, 
cex.lab=1.3, mgp=c(2.7,0.5,0), font.axis=1, lab=c(4,5,6), 
xlab=expression("Protein content"), ylab=expression("Carbohydrate 
Content"),main="Triglyceride (LW)", asp=1, xlim=c(0,38), ylim=c(0,38))
contour(surf.te.outLW, lwd=2, labcex=1, add=T)

image(surf.te.outSW, col=tim.colors(128), lwd=5, las=1, font.lab=2, 
cex.lab=1.3, mgp=c(2.7,0.5,0), font.axis=1, lab=c(4,5,6), 
xlab=expression("Protein content"), ylab=expression("Carbohydrate 
Content"),main="Triglyceride (SW)", asp=1, xlim=c(0,38), ylim=c(0,38))
contour(surf.te.outSW, lwd=2, labcex=1, add=T)

# Note how different the scales are between the two images, as indicated by the 
contour lines, but the color ranges are the same.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to