[R] several Filled.contour plots on the same device...

Billy.Requena billy.requena at gmail.com
Fri Aug 20 02:16:26 CEST 2010


Hi Alexis!

I had the same problem you faced and the solution I found was modifying the
layout function.
That’s an example:

f1 <- function (a, x) {2.15*a -0.25*x}
f2 <- function (a,x) {exp(2.36*a - 0.04*x)}
a1 <- seq(from=5.2, to=6.2, by=(6.2-5.2)/19)
b1 <- seq(0,32)
zeros <- rep(0, length(a)*length(b))
mat1 <- matrix(zeros, ncol=length(a), nrow=length(b))
 for (i in 1:20)
 {
 for(j in 1:33)
 {
 est <- f1(a=a1[i], x=b1[j])
 mat1[j,i] <- est
 }
 }

mat2 <- matrix(zeros, ncol=length(a), nrow=length(b))
 for (i in 1:20)
 {
 for(j in 1:33)
 {
 est <- f2(a=a1[i], x=b1[j])
 mat2[j,i] <- est
 }
 }


mar.orig <- (par.orig <- par(c("mar", "las", "mfrow")))$mar
w <- (3 + mar.orig[2L]) * par("csi") * 2.54
a <- layout(matrix(c(2, 1,0,4,3), ncol = 5), heights=lcm(20), widths =
c(1.2, lcm(w/1.75),0.05, 1, lcm(w/1.75)))
layout.show(a) #device dividido ppara apresentar duas figuras compostas

#Scale 1
par(las = 1)
mar <- mar.orig
mar[4L] <- mar[2L]
mar[2L] <- 1
par(mar = mar)
lev.m.vol <- pretty(range(mat1),4)
plot.new()
	plot.window(xlim=c(0, 1), ylim=range(lev.m.vol), xaxs="i", yaxs="i")
	rect(0, lev.m.vol[-length(lev.m.vol)], 1, lev.m.vol[-1L], col =
gray((6:1)/6))
	axis(4, cex.axis=1.2)
	mtext("Mean", at=2.5, side=3, line=1, adj=1, cex=1.35)

#Graph1
mar <- mar.orig
mar[4L] <- 1
par(mar = c(6,8,4,2))
plot.new()
	plot.window(xlim=range(b1, finite = TRUE), ylim=range(a1, finite = TRUE), 
		"", xaxs = "i", yaxs = "i", asp = NA)
	storage.mode(mat1) <- "double"
	.Internal(filledcontour(as.double(b1), as.double(a1), mat1, 
		as.double(lev.m.vol), col = gray((6:1)/6)))
box()
axis(1, at=seq(0,32,by=4),seq(0, 32, by =4), cex.axis=1.2)
axis(2, at=seq(5.2, 6.2, by =0.2),labels=c("5.2", "5.4", "5.6", "5.8",
"6.0", "6.2"), cex.axis=1.2)
mtext("X", side=1, line=3.5, cex =1.2)
mtext("Y", at=5.62, side=2, line=3.5, cex =1.2, las=0)
mtext("A", at=1, side=3, line=1, cex =2.2)

#Scale 2
par(las = 1)
mar <- mar.orig
mar[4L] <- mar[2L]
mar[2L] <- 1
par(mar = mar)
lev.sd.vol <- pretty(range(mat2),4)
plot.new()
	plot.window(xlim=c(0, 1), ylim=range(lev.sd.vol), xaxs="i", yaxs="i")
	rect(0, lev.sd.vol[-length(lev.sd.vol)], 1, lev.sd.vol[-1L], col =
gray((6:1)/6))
	axis(4, cex.axis=1.2)
	mtext("Standard", at=3.3, side=3, line=2.5, adj=1, cex=1.25)
	mtext("deviation", at=3.3, side=3, line=1, adj=1, cex=1.25)

#Graph2
mar <- mar.orig
mar[4L] <- 1
par(mar = c(6,1,4,2))
plot.new()
	plot.window(xlim=range(b1, finite = TRUE), ylim=range(a1, finite = TRUE), 
		"", xaxs = "i", yaxs = "i", asp = NA)
	storage.mode(mat2) <- "double"
	.Internal(filledcontour(as.double(b1), as.double(a1), mat2, 
		as.double(lev.sd.vol), col = gray((6:1)/6)))
box()
axis(1, at=seq(0,32,by=4),seq(0, 32, by =4), cex.axis=1.2)
axis(2, at=seq(5.2, 6.2, by =0.2),labels=c("5.2", "5.4", "5.6", "5.8",
"6.0", "6.2"), cex.axis=1.2)
mtext("X", side=1, line=3.5, cex =1.2)
mtext("B", at=1, side=3, line=1, cex =2.2)

I wish it could help you

Gustavo Requena
PhD student - Laboratory of Arthropod Behavior and Evolution
Universidade de São Paulo
http://ecologia.ib.usp.br/opilio/gustavo.html

-- 
View this message in context: http://r.789695.n4.nabble.com/several-Filled-contour-plots-on-the-same-device-tp819040p2332041.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list