Commit b6709467 authored by kunstler's avatar kunstler
Browse files

update merge of fig 2 and 3

parent af240982
......@@ -824,6 +824,10 @@ for (i in traits){
fun.legend(legend.pos, biomes.names, biomes.c, col.vec, pch.vec)
}
################
# MERGE FIG 2 and 3
border.size <- function(){
big.m <- 3.0
small.m <- 0
......@@ -833,21 +837,11 @@ return(list(big.m = big.m,
legend.m = legend.m) )
}
fun.layout <- function(legend.pos, b = border.size()){
if (legend.pos==1){
fun.layout <- function(b = border.size()){
wid <- c(b$big.m ,0, b$small.m) +
rep((14-b$big.m-b$small.m-b$legend.m)/3, each= 3)
m <- matrix(c(1:4), 1, 4)
m2 <- matrix(c(5:8), 1, 4)
layout(rbind(m, m2), widths=c(wid, b$legend.m), heights = c(1,1))
}
if(legend.pos==0) {
wid <- c(b$big.m ,0, b$small.m) +
rep((14-b$big.m-b$small.m)/3, each= 3)
m <- matrix(c(1:3), 1, 3)
m2 <- matrix(c(4:6), 1, 3)
layout(rbind(m, m2), widths=c(wid), heigts = c(1,1))
}
m2 <- matrix(c(1:4), 1, 4)
layout(m2, widths=c(wid, b$legend.m), heights = 1)
}
fun.param.descrip <- function(add.param.descrip.TF, x.line = -0.63){
......@@ -873,40 +867,35 @@ fun.param.descrip <- function(add.param.descrip.TF, x.line = -0.63){
}
}
fun.legend <- function(legend.pos, biomes.names, biomes.c, col.vec, pch.vec){
if (legend.pos == 1){
fun.legend <- function(biomes.names, biomes.c, col.vec, pch.vec){
par(mar=c(0, 0, 0, 0))
plot(0:1,0:1,type="n", axes=FALSE, xlab="", ylab="")
points(rep(0.5,length(biomes.c)), 0.25+(length(biomes.c):1-1)*0.15,
col = col.vec[biomes.c],
pch = pch.vec[biomes.c],
points(rep(0.5,length(biomes.c)+1), 0.15+((length(biomes.c)+1):1-1)*0.15,
col = c('black', col.vec[biomes.c]),
pch = c(15, pch.vec[biomes.c]),
cex = 2)
segments(rep(0.40,length(biomes.c)), 0.25+(length(biomes.c):1-1)*0.15,
rep(0.60,length(biomes.c)), 0.25+(length(biomes.c):1-1)*0.15,
lty =1, lwd = 1.5,col = col.vec[biomes.c])
text(rep(0.5,length(biomes.c)), 0.2+(length(biomes.c):1-1)*0.15,
labels = biomes.names[biomes.c], cex= 1.8)
}
if (legend.pos == 2){
par(mar=c(0, 0, 0, 0))
plot(1,1,type="n", axes=FALSE, xlab="", ylab="")
legend(1.2 , 1.5, legend = biomes.names[biomes.c], col = col.vec[biomes.c],
pch = pch.vec[biomes.c], lty =1, lwd = 1.7,
bty = 'n', cex = 2, ncol = 2, xpd = TRUE, y.intersp =2, adj = c(1,1.5))
}
points(rep(0.5,1), 0.15+((length(biomes.c)+1)-1)*0.15,
col = c('black'),
pch = c(15),
cex = 2.5)
segments(rep(0.40,length(biomes.c)+1), 0.15+((length(biomes.c)+1):1-1)*0.15,
rep(0.60,length(biomes.c)+1), 0.15+((length(biomes.c)+1):1-1)*0.15,
lty =1, lwd = 1.5,col = c('black', col.vec[biomes.c]))
segments(rep(0.40, 1), 0.15+(length(biomes.c)+1-1)*0.15,
rep(0.60, 1), 0.15+(length(biomes.c)+1-1)*0.15,
lty =1, lwd = 2,col = 'black')
text(rep(0.5,length(biomes.c)+1), 0.11+((length(biomes.c)+1):1-1)*0.15,
labels = c('mean', biomes.names[biomes.c]), cex= 1.8)
}
fun.par.mai <- function(i, traits, b, type=2){
fun.par.mai <- function(i, traits, b){
if(i == traits[1]) {
if (type == 1) par(mai=c(0.7, b$big.m,0.2,0), xpd = TRUE)
if (type == 2) par(mai=c(0.2, b$big.m,0.7,0), xpd = TRUE)
par(mai=c(0.8, b$big.m,0.7,0), xpd = TRUE)
}else{
if(type ==1) par(mai=c(0.7,0,0.2,0), xpd = TRUE)
if(type ==2) par(mai=c(0.2,0,0.7,0), xpd = TRUE)
par(mai=c(0.8,0,0.7,0), xpd = TRUE)
}
if(i == traits[length(traits)]) {
if(type ==1) par(mai=c(0.7,0,0.2,b$small.m), xpd = TRUE)
if(type ==2) par(mai=c(0.2,0,0.7,b$small.m), xpd = TRUE)
par(mai=c(0.8,0,0.7,b$small.m), xpd = TRUE)
}
}
......@@ -930,66 +919,42 @@ plot.param.mean.and.biomes.fixed <- function(list.res,
col.vec,
pch.vec,
names.bio,
legend.pos = 1,
add.param.descrip.TF = 1,
...){
if(! add.param.descrip.TF %in% 0:2) stop("add.param.descrip.TF need to be in 0 1 2")
col.vec[2] <- col.vec[1]
biomes.c <- as.character(biomes)
fun.layout(legend.pos)
fun.layout()
b <- border.size()
## model mean models 1
for (i in traits){
list.temp <- list.res[[paste(data.type, "_", i ,
"_", models[1],
sep = '')]]$lmer.summary
param.mean <- list.temp$fixed.coeff.E[param.vec]
param.std <- list.temp$fixed.coeff.Std.Error
names(param.std) <- names(list.temp$fixed.coeff.E)
param.std <- param.std[param.vec]
param.BLUP <- list.temp$set.BLUP
fun.par.mai(i, traits, b)
plot(param.mean[param.print], (1:length(param.vec))[param.print],
yaxt = 'n', xlab = NA, ylab = NA,
pch = 16, cex = 2.5, cex.lab = 1.7, cex.axis = 1.5,
ylim = range(1-0.21, length(param.vec)+0.21),
...)
mtext(traits.names[i], side=3, cex =1.7, line = 1)
box(lwd= 2)
lines(c(0, 0), c(1-0.38, length(param.vec)+0.38), cex = 1.7)
if(i == traits[1]) {lapply(1:length(param.vec),
fun.axis.one.by.one,
side = 2,
labels = param.names,
cols.vec = col.names[param.vec])
fun.param.descrip(add.param.descrip.TF)
}
fun.plot.error.bar.horiz(param.mean[param.print],
(1:length(param.vec))[param.print],
param.std[param.print], lwd= 1.5)
}
plot(1,1,type="n", axes=FALSE, xlab="", ylab="")
##################################
## model fixed biomes
for (i in traits){
list.temp <- list.res[[paste0(data.type, "_", i ,
"_", models[2])]]
fun.par.mai(i, traits, b, type = 1)
## GET VAR
list.temp.m <- list.res[[paste(data.type, "_", i ,
"_", models[1],
sep = '')]]$lmer.summary
param.mean.m <- list.temp.m$fixed.coeff.E[param.vec]
param.std.m <- list.temp.m$fixed.coeff.Std.Error
names(param.std.m) <- names(list.temp.m$fixed.coeff.E)
param.std.m <- param.std.m[param.vec]
fun.par.mai(i, traits, b)
## LOOP OVER VAR
for (n.vars in seq_len(length(param.vec))){
list.fixed <- fun.get.fixed.biomes(param.vec[n.vars], list.temp,
biomes.vec = biomes)
param.mean <- list.fixed$fixed.biomes
param.std <- list.fixed$fixed.biomes.std
seq.jitter <- seq(25, -25, length.out = length(biomes))/120
seq.jitter <- seq(25, -25, length.out = length(biomes)+1)/120
if(n.vars == 1){
plot(param.mean, seq.jitter+n.vars,
plot(c(param.mean.m[n.vars], param.mean), seq.jitter+n.vars,
yaxt = 'n', xlab = NA, ylab = NA,
, pch = pch.vec[biomes.c] , cex = 2, cex.axis = 1.5, cex.lab = 1.7,
pch = c(15, pch.vec[biomes.c]) , cex = 2,
cex.axis = 1.5, cex.lab = 1.7,
ylim = range(1-0.21, length(param.vec)+0.21),
col = col.vec[biomes.c], ...)
col = c('black', col.vec[biomes.c]), ...)
mtext('', side=3, cex =1.7, line = 1)
box(lwd= 2)
lines(c(0, 0), c(1-0.38, length(param.vec)+0.38), lwd= 1)
......@@ -1005,15 +970,24 @@ for (i in traits){
line = 4)}
}
if(n.vars != 1){
points(param.mean, seq.jitter+n.vars,
col = col.vec[biomes.c], pch = pch.vec[biomes.c], cex = 2)
points(c(param.mean.m[n.vars], param.mean), seq.jitter+n.vars,
col = c('black', col.vec[biomes.c]),
pch = c(15, pch.vec[biomes.c]), cex = 2)
}
fun.plot.error.bar.horiz(param.mean,
seq.jitter+n.vars,
seq.jitter[-1]+n.vars,
param.std, col = col.vec[biomes.c], lwd= 1.2)
}
points(param.mean.m, seq.jitter[1]+1:n.vars,
pch = 15, cex = 2.5)
fun.plot.error.bar.horiz(param.mean.m,
seq.jitter[1]+1:n.vars,
param.std.m, col = 'black', lwd= 2)
mtext(traits.names[i], side=3, cex =1.5, line = 1)
}
fun.legend(legend.pos, biomes.names, biomes.c, col.vec, pch.vec)
fun.legend( biomes.names, biomes.c, col.vec, pch.vec)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment