# NOT RUN {
library(utils)
data(gp.rwl)
data(gp.po)
gp.rwi <- cms(rwl = gp.rwl, po = gp.po)
gp.ids <- read.ids(gp.rwl, stc = c(0, 2, 1))
# On a running window
rwi.stats.running(gp.rwi, gp.ids)
## With no running window (i.e. running.window = FALSE)
rwi.stats(gp.rwi, gp.ids)
## Restrict to common overlap (in this case 1899 to 1987)
rwi.stats(gp.rwi, gp.ids, period="common")
rwi.stats.legacy(gp.rwi, gp.ids) # rwi.stats prior to dplR 1.5.3
# }
# NOT RUN {
library(graphics)
def.par <- par(no.readonly=TRUE)
## Plot the chronology showing a potential cutoff year based on EPS
eps.cut <- 0.92 # An arbitrary EPS cutoff for demonstration
gp.crn <- chron(gp.rwi)
## Running stats on the rwi with an window
foo <- rwi.stats.running(gp.rwi, gp.ids, window.length = 80)
yrs <- time(gp.crn)
bar <- data.frame(yrs = c(min(yrs), foo$mid.year, max(yrs)),
eps = c(NA, foo$eps, NA))
par(mar = c(2, 2, 2, 2), mgp = c(1.1, 0.1, 0), tcl = 0.25,
mfcol = c(2, 1), xaxs='i')
plot(yrs, gp.crn[, 1], type = "n", xlab = "Year",
ylab = "RWI", axes=FALSE)
cutoff <- max(bar$yrs[bar$eps < eps.cut], na.rm = TRUE)
xx <- c(500, 500, cutoff, cutoff)
yy <- c(-1, 3, 3, -1)
polygon(xx, yy, col = "grey80")
abline(h = 1, lwd = 1.5)
lines(yrs, gp.crn[, 1], col = "grey50")
lines(yrs, ffcsaps(gp.crn[, 1], nyrs = 32), col = "red", lwd = 2)
axis(1); axis(2); axis(3);
par(new = TRUE)
## Add EPS
plot(bar$yrs, bar$eps, type = "b", xlab = "", ylab = "",
axes = FALSE, pch = 20, col = "blue")
axis(4, at = pretty(foo$eps))
mtext("EPS", side = 4, line = 1.1)
box()
## Second plot is the chronology after the cutoff only
## Chronology is rebuilt using just years after cutoff but
## that difference is essentially nil.
yr.mask <- yrs > cutoff
yrs2 <- yrs[yr.mask]
gp.crn2 <- chron(gp.rwi[yr.mask, ])
plot(yrs2, gp.crn2[, 1], type = "n",
xlab = "Year", ylab = "RWI", axes=FALSE)
abline(h = 1, lwd = 1.5)
lines(yrs2, gp.crn2[, 1], col = "grey50")
lines(yrs2, ffcsaps(gp.crn2[, 1], nyrs = 32),
col = "red", lwd = 2)
axis(1); axis(2); axis(3); axis(4)
box()
par(def.par)
# }
Run the code above in your browser using DataLab