library(lattice) load("d.RData") plot.trees <- function(v.id, layout = c(4, 3), stem = TRUE) { df.b <- df.branch[df.branch$id %in% v.id,] df.t <- df.tree[df.tree$id %in% v.id,] df.b$id <- factor(df.b$id, levels = v.id) df.t$id <- factor(df.t$id, levels = v.id) min.x <- min(log(df.b$bdiameter08), na.rm = TRUE) max.x <- max(log(df.b$bdiameter08), na.rm = TRUE) max.y <- max(df.t$height08) + 10 strip.tree <- function(which.panel, ...) { id <- v.id[which.panel] dt <- df.t[df.t$id == id,] panel.rect( 0, 0, 1, 1, col = c("#ccffcc", "#ffcccc")[(dt["species"] == "mo") + 1] ) panel.text( 0.5, 0.5, sprintf("%s (H = %.1f)", v.id[which.panel], dt["height08"]) ) } panel.tree <- function(x, y, subscripts, ...) { dfs <- df.b[subscripts,] id <- dfs[1, "id"] # lines (top at 2007, ground) panel.rect( min.x, -df.t[df.t$id == id, "dH"], max.x, 0, col = "#ddddff", border = NA ) panel.rect( min.x, -df.t[df.t$id == id, "height08"], max.x, -max.y, col = "#eeeedd", border = NA ) y <- dfs$bposition08 # stem growth if (stem) { md <- 0.5 panel.polygon( c(min.x, log(dfs$sdiameter08 * md), min.x), c(-min(y), -y, -max(y)), col = "#cccccc", border = NA ) s07 <- !is.na(dfs$sdiameter07) panel.polygon( c(min.x, log(dfs$sdiameter07[s07] * md), min.x), c(-min(y[s07]), -y[s07], -max(y[s07])), col = "#eeeeee", border = NA ) } # branch growth panel.segments( log(dfs$bdiameter08), -y, log(dfs$bdiameter07), -y, lwd = 2, col = "#00aa00" ) # diamerter 08 and 07 panel.points( log(dfs$bdiameter08), -y, pch = c(24,8, 23)[dfs$new08 + dfs$proleptic08 + 1], col = c("#000000", "#ff4000")[dfs$new08 + 1] ) panel.points( log(dfs$bdiameter07), -y, pch = c(21, 4)[dfs$dead08 + 1], col = c("#000000", "#0000ff")[dfs$dead08 + 1] ) } print(xyplot( -bposition08 ~ log(bdiameter08) | id, data = df.b, xlim = c(min.x, max.x), ylim = c(-max.y, 0), panel = panel.tree, strip = strip.tree, layout = layout, xlab = "log(D)", ylab = "Depth (cm)" )) } plot.spc <- function(spc = "bp", ...) { df.t <- df.tree[df.tree$species == spc,] v.id <- df.t[order(df.t$height08), "id"] plot.trees(v.id, ...) } plot.all <- function() { for (spc in c("bp", "mo")) { file <- sprintf("trees%s.pdf", spc) cat("# output to", file, "...\n") pdf( file = file, paper = "A4", width = 8, height = 12 ) plot.spc(spc) dev.off() } }