Commit 12ab032f authored by Georges Kunstler's avatar Georges Kunstler
Browse files

fixed knitr

parent 5ec5b812
output
output_cluster
trait.workshop
ignore
data/raw*
figs
......
source("R/utils/plot.R")
source("R/utils/plot.biomes.R")
#read.data
......
......@@ -60,6 +60,22 @@ names(col.vec) <- sets
pch.vec <- 1:length(sets)
names(pch.vec) <- sets
## biomes
col.vec.biomes <- make.transparent(c("navajowhite3", "darkgoldenrod1",
"sienna","darkolivegreen4",
"darkseagreen3", "forestgreen",
"darkgreen","olivedrab","gray"),
0.9)
names(col.vec.biomes) <-
c('Subtropical desert', 'Temperate grassland desert',
'Woodland shrubland', 'Temperate forest',
'Boreal forest', 'Temperate rain forest',
'Tropical rain forest', 'Tropical forest savanna',
'Tundra')
pch.vec.biomes <-seq_along(col.vec.biomes)
names(pch.vec.biomes) <- names(col.vec.biomes)
## Position label at a fractional x/y position on a plot
......@@ -149,197 +165,3 @@ boxplot(y~x.cut,at=mid.points,outline=FALSE,names=round(mid.points,0),
}
### PLOTS function for biomes
library(sp)
biomes.data <- read.csv('R/utils/biomes.csv', stringsAsFactors = FALSE)
list.coord <- lapply(unique(biomes.data$biome),
function(biome.id,data) cbind(data$y[data$biome == biome.id] * 10,
data$x[data$biome == biome.id]),
data=biomes.data)
names(list.coord) <- unique(biomes.data$biome)
list.Polygon <- lapply(list.coord, Polygon)
list.Polygons <- lapply(1:length(list.Polygon),
function(i, x) {Polygons(list(x[[i]]), names(x)[i])},
x = list.Polygon)
poly.biomes <- SpatialPolygons(list.Polygons)
DF <- data.frame(biomes= names(poly.biomes), row.names = names(poly.biomes))
poly.DF <- SpatialPolygonsDataFrame(poly.biomes, DF)
## creat object for polygon of whitaker
list.poly <-
list(tropical_rainforest = cbind(x = c(260,450,350,250,260),
y = c(30,30,20,20,30)),
temperate_rainforest = cbind(x = c(250,350,200,160,250),
y = c(20,20,5,5,20)),
tropical_montane_forest = cbind(x = c(160,200,150,120,160),
y = c(5,5,0,0,5)),
alpine_shrubland = cbind(x = c(120,150,100,80,120),
y = c(0,0,-5,-5,0)),
tropical_deciduous_forest = cbind(x = c(140,260,250,130,140),
y = c(30,30,20,20,30)),
temperate_forest = cbind(x = c(130,250,160,60,130),
y = c(20,20,5,3,20)),
boreal = cbind(x = c(60,160,80,50,60),
y = c(3,5,-5,-5,3) ),
tropical_woodland = cbind(x = c(50,140,130,37,50),
y = c(30,30,20,20,30) ),
temperate_woodland = cbind(x = c(37,130,60,50,0,37),
y = c(20,20,3,-5,-5,20)),
cold_desert = cbind(x = c(0,23,0,0),
y = c(10,10,-5,10)),
hot_desert = cbind(x = c(0,50,23,0,0),
y = c(30,30,10,10,30)),
tundra = cbind(x = c(0,100,0,0),
y = c(-5,-5,-15,-5)))
list.Polygon <- lapply(list.poly, Polygon)
list.Polygons <- lapply(1:length(list.Polygon),
function(i, x) {Polygons(list(x[[i]]), names(x)[i])},
x = list.Polygon)
poly.biomes <- SpatialPolygons(list.Polygons)
DF <- data.frame(biomes= names(poly.biomes), row.names = names(poly.biomes))
poly.DF2 <- SpatialPolygonsDataFrame(poly.biomes, DF)
## col.vec.biomes
col.vec.biomes <- make.transparent(c("navajowhite3", "darkgoldenrod1",
"sienna","darkolivegreen4",
"darkseagreen3", "forestgreen",
"darkgreen","olivedrab","gray"),
0.9)
names(col.vec.biomes) <- poly.DF$biomes
pch.vec.biomes <-1:length(poly.DF$biomes)
names(pch.vec.biomes) <- poly.DF$biomes
## function to overlay points on biomes
fun.overly.plot.on.biomes <- function(MAP, MAT, names.vec, poly = poly.DF){
xy = cbind(MAP, MAT)
dimnames(xy)[[1]] = names.vec
pts = SpatialPoints(xy)
return(over(pts, poly))
}
plot.biome.map <- function(poly = poly.DF){
require(sp)
# MAKE EMPTY PLOT
plot(0,0, type = 'n', xlim = c(0, 450), ylim = c(30, -15),
xlab = "Mean annual precipitation (cm)",
ylab = "Mean annual temperature (deg C)")
# MAKE POLYGONS
plot(poly,col = make.transparent(c("navajowhite3", "darkgoldenrod1",
"sienna","darkolivegreen4",
"darkseagreen3", "forestgreen",
"darkgreen","olivedrab","gray"),
0.9),
border = NA,
add = TRUE)
}
plot.points.on.biome.map.diff.tropical <- function(MAP, MAT, set,ecocode,
cols = niceColors(),
add.legend=TRUE){
plot.biome.map()
col <- c()
pch <- c()
cex <- c()
sets <- unique(set)
for(i in 1:length(sets)){
j <- (set == sets[i])
if(unique(ecocode[j])[1]=='tropical') {
col <- c(col,make.transparent(cols[i],0.75))
pch <- c(pch,16)
cex <- c(cex,1.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
}else{
col <- c(col,make.transparent(cols[i],0.25))
pch <- c(pch,16)
cex <- c(cex,.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
}
}
if(add.legend)
legend("topright", pch = pch, legend = sets, bty = "n", col = col, cex = 1)
}
plot.points.on.biome.map.ecocode <- function(MAP, MAT, MAP.sd, MAT.sd, set,
ecocode, cols = niceColors(),
add.legend = TRUE){
plot.biome.map()
col <- c()
pch <- c()
cex <- c()
sets <- unique(set)
for(i in 1:length(sets)){
j <- (set == sets[i])
col <- c(col,make.transparent(cols[i],0.99))
pch <- c(pch,16)
cex <- c(cex,1.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
segments(MAP[j], MAT[j]-MAT.sd[j],MAP[j], MAT[j]+MAT.sd[j], col = col[i])
segments(MAP[j]-MAP.sd[j], MAT[j],MAP[j]+MAP.sd[j], MAT[j], col = col[i])
}
if(add.legend)
legend("topright", pch = pch, legend = sets, bty = "n", col = col, cex = 1)
}
plot.points.on.biome.map <- function(MAP, MAT, set, cols = col.vec){
plot.biome.map()
points(MAP, MAT, col = cols[set])
}
plot.points.on.biome.map.panel <- function(MAP, MAT, set, ecocode,
cols = niceColors()[-c(1)]){
sets <- unique(set)
nsets <- length(sets)
par(mfrow=c(ceiling(nsets/2),2), mar = c(4,3,3,2))
for(i in 1:nsets){
j <- (set == sets[i])
plot.points.on.biome.map(MAP[j], MAT[j], set[j])
title(sets[i])
}
}
plot.ellips.on.biome.map <- function(MAP, MAT, set,
cols = col.vec, lty.vec = pch.vec){
plot.biome.map()
lapply(unique(set), fun.ellipsoid.hull,
x = MAP, y = MAT, sets.v = set,
col.vec = cols, lty.vec = lty.vec)
legend("topright", pch = 16, legend = names(col.vec), bty = "n",
col = col.vec, ncol = 2)
}
fun.ellipsoid.hull <- function(set, x, y, sets.v, col.vec, lty.vec){
require(cluster)
xy <- cbind(x[sets.v==set], y[sets.v==set])
if (nrow(xy)>10){
xy <- xy[!is.na(xy[, 1]) & !is.na(xy[, 2]), ]
xy <- xy[xy[, 1]>quantile(xy[, 1], 0.01) &xy[, 1]<quantile(xy[, 1], 0.99) &
xy[, 2]>quantile(xy[, 2], 0.01) &xy[, 2]<quantile(xy[, 2], 0.99), ]
exy <- ellipsoidhull(xy)
lines(predict(exy), col = col.vec[set], lwd = 3)
}else{
points(x[sets.v==set], y[sets.v==set] , col = col.vec[set],
cex = 2.5, pch = 16)
}
}
### PLOTS function for biomes
library(sp)
biomes.data <- read.csv('R/utils/biomes.csv', stringsAsFactors = FALSE)
list.coord <- lapply(unique(biomes.data$biome),
function(biome.id,data) cbind(data$y[data$biome == biome.id] * 10,
data$x[data$biome == biome.id]),
data=biomes.data)
names(list.coord) <- unique(biomes.data$biome)
list.Polygon <- lapply(list.coord, Polygon)
list.Polygons <- lapply(1:length(list.Polygon),
function(i, x) {Polygons(list(x[[i]]), names(x)[i])},
x = list.Polygon)
poly.biomes <- SpatialPolygons(list.Polygons)
DF <- data.frame(biomes= names(poly.biomes), row.names = names(poly.biomes))
poly.DF <- SpatialPolygonsDataFrame(poly.biomes, DF)
## col.vec.biomes
## function to overlay points on biomes
fun.overly.plot.on.biomes <- function(MAP, MAT, names.vec, poly = poly.DF){
xy = cbind(MAP, MAT)
dimnames(xy)[[1]] = names.vec
pts = SpatialPoints(xy)
return(over(pts, poly))
}
plot.biome.map <- function(poly = poly.DF){
require(sp)
# MAKE EMPTY PLOT
plot(0,0, type = 'n', xlim = c(0, 450), ylim = c(30, -15),
xlab = "Mean annual precipitation (cm)",
ylab = "Mean annual temperature (deg C)")
# MAKE POLYGONS
plot(poly,col = make.transparent(c("navajowhite3", "darkgoldenrod1",
"sienna","darkolivegreen4",
"darkseagreen3", "forestgreen",
"darkgreen","olivedrab","gray"),
0.9),
border = NA,
add = TRUE)
}
plot.points.on.biome.map.diff.tropical <- function(MAP, MAT, set,ecocode,
cols = niceColors(),
add.legend=TRUE){
plot.biome.map()
col <- c()
pch <- c()
cex <- c()
sets <- unique(set)
for(i in 1:length(sets)){
j <- (set == sets[i])
if(unique(ecocode[j])[1]=='tropical') {
col <- c(col,make.transparent(cols[i],0.75))
pch <- c(pch,16)
cex <- c(cex,1.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
}else{
col <- c(col,make.transparent(cols[i],0.25))
pch <- c(pch,16)
cex <- c(cex,.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
}
}
if(add.legend)
legend("topright", pch = pch, legend = sets, bty = "n", col = col, cex = 1)
}
plot.points.on.biome.map.ecocode <- function(MAP, MAT, MAP.sd, MAT.sd, set,
ecocode, cols = niceColors(),
add.legend = TRUE){
plot.biome.map()
col <- c()
pch <- c()
cex <- c()
sets <- unique(set)
for(i in 1:length(sets)){
j <- (set == sets[i])
col <- c(col,make.transparent(cols[i],0.99))
pch <- c(pch,16)
cex <- c(cex,1.25)
points(MAP[j], MAT[j], pch = pch[i], col = col[i], cex=cex[i])
segments(MAP[j], MAT[j]-MAT.sd[j],MAP[j], MAT[j]+MAT.sd[j], col = col[i])
segments(MAP[j]-MAP.sd[j], MAT[j],MAP[j]+MAP.sd[j], MAT[j], col = col[i])
}
if(add.legend)
legend("topright", pch = pch, legend = sets, bty = "n", col = col, cex = 1)
}
plot.points.on.biome.map <- function(MAP, MAT, set, cols = col.vec){
plot.biome.map()
points(MAP, MAT, col = cols[set])
}
plot.points.on.biome.map.panel <- function(MAP, MAT, set, ecocode,
cols = niceColors()[-c(1)]){
sets <- unique(set)
nsets <- length(sets)
par(mfrow=c(ceiling(nsets/2),2), mar = c(4,3,3,2))
for(i in 1:nsets){
j <- (set == sets[i])
plot.points.on.biome.map(MAP[j], MAT[j], set[j])
title(sets[i])
}
}
plot.ellips.on.biome.map <- function(MAP, MAT, set,
cols = col.vec, lty.vec = pch.vec){
plot.biome.map()
lapply(unique(set), fun.ellipsoid.hull,
x = MAP, y = MAT, sets.v = set,
col.vec = cols, lty.vec = lty.vec)
legend("topright", pch = 16, legend = names(col.vec), bty = "n",
col = col.vec, ncol = 2)
}
fun.ellipsoid.hull <- function(set, x, y, sets.v, col.vec, lty.vec){
require(cluster)
xy <- cbind(x[sets.v==set], y[sets.v==set])
if (nrow(xy)>10){
xy <- xy[!is.na(xy[, 1]) & !is.na(xy[, 2]), ]
xy <- xy[xy[, 1]>quantile(xy[, 1], 0.01) &xy[, 1]<quantile(xy[, 1], 0.99) &
xy[, 2]>quantile(xy[, 2], 0.01) &xy[, 2]<quantile(xy[, 2], 0.99), ]
exy <- ellipsoidhull(xy)
lines(predict(exy), col = col.vec[set], lwd = 3)
}else{
points(x[sets.v==set], y[sets.v==set] , col = col.vec[set],
cex = 2.5, pch = 16)
}
}
\relax
\@writefile{toc}{\contentsline {section}{\numberline {1}Growth model and competitive growth reduction/inhibition}{1}}
\newlabel{eq:G1}{{1}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {2}Approach to include traits effect on competitive effect and competitive response}{1}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Absolute and hierarchical distance}{2}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Effect/response model}{2}}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.2.1}Additive model of competitive effect and response}{2}}
\newlabel{addinter}{{8}{3}}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.2.2}Multiplicative model of competitive effect and response}{3}}
\newlabel{mult}{{12}{3}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Comparison of the multiplicative and additive effect/response model}{3}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.4}How Competitive effect/response model compare with the hierarchical distance and absolute distance model}{4}}
\@writefile{toc}{\contentsline {section}{\numberline {3}Choice of model to fit}{4}}
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Are competitive effect and response additive or multiplicative?}{4}}
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Variation of competition parameter in function of $t_f$ and $t_n$ for hierarchical distance and absolute distance and respective best fit of additive or multiplicative model. For the hierarchical distance $\lambda = 0.5-0.5*t_f+0.5*t_n$ , for the absolute distance $\lambda = 1-\delimiter "026A30C t_n-t_f\delimiter "026A30C $\relax }}{5}}
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
\newlabel{fig:competmodel}{{1}{5}}
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Shift in facilitation in the multiplicative model similar to absolute distance.\relax }}{6}}
\newlabel{fig:competfacill}{{2}{6}}
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces Four alternative additive E/R models.\relax }}{7}}
\newlabel{fig:add}{{3}{7}}
\@writefile{lof}{\contentsline {figure}{\numberline {4}{\ignorespaces Four alternative multiplicative E/R models.\relax }}{8}}
\newlabel{fig:mult}{{4}{8}}
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}Alternative models}{9}}
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2013.4.11) 3 OCT 2013 16:46
entering extended mode
%&-line parsing enabled.
**\input Traits.compet.theo.tex
(./Traits.compet.theo.tex (/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size11.clo
File: size11.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
)
(/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
(/usr/share/texmf-texlive/tex/latex/graphics/trig.sty
Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
)
(/etc/texmf/tex/latex/config/graphics.cfg
File: graphics.cfg 2009/08/28 v1.8 graphics configuration of TeX Live
)
Package graphics Info: Driver file: pdftex.def on input line 91.
(/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def
File: pdftex.def 2010/03/12 v0.04p Graphics/color for pdfTeX
\Gread@gobject=\count87
))
\Gin@req@height=\dimen103
\Gin@req@width=\dimen104
)
(/usr/share/texmf-texlive/tex/latex/graphics/epsfig.sty
Package: epsfig 1999/02/16 v1.7a (e)psfig emulation (SPQR)
\epsfxsize=\dimen105
\epsfysize=\dimen106
)
(/usr/share/texmf-texlive/tex/latex/setspace/setspace.sty
Package: setspace 2000/12/01 6.7 Contributed and Supported LaTeX2e package
Package: `setspace' 6.7 <2000/12/01>
) (/usr/share/texmf-texlive/tex/latex/subfig/subfig.sty
Package: subfig 2005/06/28 ver: 1.3 subfig package
(/usr/share/texmf-texlive/tex/latex/caption/caption.sty
Package: caption 2009/10/09 v3.1k Customizing captions (AR)
(/usr/share/texmf-texlive/tex/latex/caption/caption3.sty
Package: caption3 2009/10/09 v3.1k caption3 kernel (AR)
\captionmargin=\dimen107
\captionmargin@=\dimen108
\captionwidth=\dimen109
\caption@indent=\dimen110
\caption@parindent=\dimen111
\caption@hangindent=\dimen112
)
\c@ContinuedFloat=\count88
)
\c@KVtest=\count89
\sf@farskip=\skip43
\sf@captopadj=\dimen113
\sf@capskip=\skip44
\sf@nearskip=\skip45
\c@subfigure=\count90
\c@subfigure@save=\count91
\c@lofdepth=\count92
\c@subtable=\count93
\c@subtable@save=\count94
\c@lotdepth=\count95
\sf@top=\skip46
\sf@bottom=\skip47
)
(/usr/share/texmf-texlive/tex/latex/ltxmisc/url.sty
\Urlmuskip=\muskip10
Package: url 2006/04/12 ver 3.3 Verb mode for urls, etc.
)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty
Package: amsmath 2000/07/18 v2.13 AMS math features
\@mathmargin=\skip48
For additional information on amsmath, use the `?' option.
(/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01
(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0
\@emptytoks=\toks15
\ex@=\dimen114
))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d
\pmbraise@=\dimen115
)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty
Package: amsopn 1999/12/14 v2.01 operator names
)
\inf@bad=\count96
LaTeX Info: Redefining \frac on input line 211.
\uproot@=\count97
\leftroot@=\count98
LaTeX Info: Redefining \overline on input line 307.
\classnum@=\count99
\DOTSCASE@=\count100
LaTeX Info: Redefining \ldots on input line 379.
LaTeX Info: Redefining \dots on input line 382.
LaTeX Info: Redefining \cdots on input line 467.
\Mathstrutbox@=\box26
\strutbox@=\box27
\big@size=\dimen116
LaTeX Font Info: Redeclaring font encoding OML on input line 567.
LaTeX Font Info: Redeclaring font encoding OMS on input line 568.
\macc@depth=\count101
\c@MaxMatrixCols=\count102
\dotsspace@=\muskip11
\c@parentequation=\count103
\dspbrk@lvl=\count104
\tag@help=\toks16
\row@=\count105
\column@=\count106
\maxfields@=\count107
\andhelp@=\toks17
\eqnshift@=\dimen117
\alignsep@=\dimen118
\tagshift@=\dimen119
\tagwidth@=\dimen120
\totwidth@=\dimen121
\lineht@=\dimen122
\@envbody=\toks18
\multlinegap=\skip49
\multlinetaggap=\skip50
\mathdisplay@stack=\toks19
LaTeX Info: Redefining \[ on input line 2666.
LaTeX Info: Redefining \] on input line 2667.
)
(/usr/share/texmf-texlive/tex/latex/preprint/fullpage.sty
Package: fullpage 1999/02/23 1.1 (PWD)
\FP@margin=\skip51
)
(./Traits.compet.theo.aux)
\openout1 = `Traits.compet.theo.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
(/usr/share/texmf-texlive/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count108
\scratchdimen=\dimen123
\scratchbox=\box28
\nofMPsegments=\count109