paired <- function() { set.seed(1) d <- do.call(rbind, lapply(c("T1", "T2"), function(s) data.frame(sim = s, Date = as.Date("2001-10-31") + (0:7) * 365, variable = "wrr", obs = seq(5000, 9000, length.out = 8), stringsAsFactors = FALSE))) d$pred <- d$obs * runif(nrow(d), 0.9, 1.1) d } test_that("stats_by = character(0) pools even when points are coloured", { p <- plot_one2one(paired(), group = "sim", stats_by = character(0)) lab <- Filter(function(x) inherits(x$geom, "GeomText"), p$layers)[[1]]$data$lab expect_length(lab, 1L) expect_true(grepl("n = 16", lab)) }) test_that("stats_by splits the corner box when asked", { p <- plot_one2one(paired(), group = "sim", stats_by = "sim", facet = "sim") lab <- Filter(function(x) inherits(x$geom, "GeomText"), p$layers)[[1]]$data$lab expect_length(lab, 2L) expect_true(all(grepl("n = 8", lab))) }) test_that("a faceted plot gets one box per panel, never a repeated pooled box", { d <- paired() d$phase <- factor(rep(c("Calibration", "Validation"), each = 8)) p <- plot_one2one(d, facet = "phase", stats_by = c("phase", "sim")) lab <- Filter(function(x) inherits(x$geom, "GeomText"), p$layers)[[1]]$data expect_equal(nrow(lab), 2L) expect_equal(sort(as.character(lab$phase)), c("Calibration", "Validation")) }) test_that("the corner box agrees with gof() for the same grouping", { d <- paired() p <- plot_one2one(d, stats_by = character(0), stats = c("n", "rmse")) lab <- Filter(function(x) inherits(x$geom, "GeomText"), p$layers)[[1]]$data$lab g <- gof("obs", "pred", data = d) expect_true(grepl(sprintf("RMSE = %.2f", g$rmse), lab, fixed = TRUE)) })