## A practical guide to ecological modelling – Chapter 2

``````## =============================================================================
## R-Code to make figure 2.20 from the book:
## K. Soetaert  and  P.M.J. Herman, 2009.
## A practical guide to ecological modelling -
## using R as a simulation platform. Springer, 372 pp.
## http://www.springer.com/life+sciences/ecology/book/978-1-4020-8623-6 .
## implemented by Karline Soetaert
## =============================================================================

par(mar = c(1, 1, 1, 1))
names <- c("PHYTO", "DIN", "ZOO", "DETRITUS")

M <- matrix(nrow = 4, ncol = 4, byrow = TRUE, data = c(
#   p n z  d
0,1,0, 0, #p
0,0,4, 6, #n
2,0,0, 0, #z
0,0,5, 0  #d
))

pp <- plotmat(M, pos = c(1, 2, 1), curve = 0, name = names,
lwd = 1, my = 0.0, cex.txt = 0.8, prefix = "f",
box.lwd = 2, box.size = 0.08, box.type = "square",
box.prop = 0.5, arr.type = "triangle", arr.pos = 0.6,
shadow.size = 0.01, main = "NPZD")

# extra arrows: flow 5 to Detritus and flow 2 to detritus
phyto    <- pp\$comp[names == "PHYTO"]
zoo      <- pp\$comp[names == "ZOO"]
nh3      <- pp\$comp[names == "DIN"]
detritus <- pp\$comp[names == "DETRITUS"]

# flow2-> detritus
m2    <- 0.5*(zoo+phyto)
m1    <- detritus
m1 <- m1+ pp\$radii[3,1]*0.2
m1 <- m1 + pp\$radii[3,2]
mid <- straightarrow (to = m1, from = m2,
arr.type = "triangle", arr.pos = 0.7, lwd = 1)
text(mid-0.01, mid+0.03, "f3", cex = 0.8)

m1 <- 0.5*(nh3 + phyto)
m2 <- c(0.25, 0.8)
segments (m1, m1, m2, m2, lwd = 1, lty = 2)
text(m2-0.01, m2+0.03, "solar radiation", adj = c(0.5,0.5))

# chlorophyll
m1    <- phyto
m1 <- m1+ pp\$radii[1,1]
m2    <- m1
m2 <- m2+0.25
segments (m1, m1, m2, m2, lwd = 1)