## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 6
)

## ----data---------------------------------------------------------------------
library(modelskill)

set.seed(123)

n <- 150

obs <- seq(0, 10, length.out = n) +
  rnorm(n, sd = 1)

models <- list(
  Good = obs + rnorm(n, sd = 0.5),

  # Constant positive offset: strong bias, but correlation and
  # variability are almost unchanged.
  Biased = obs + 1.5,

  # Reduced variability around the observed mean.
  Smooth = mean(obs) +
    0.55 * (obs - mean(obs)) +
    rnorm(n, sd = 0.15),

  # Similar mean but much larger random error.
  Noisy = obs + rnorm(n, sd = 2),

  # Similar variability but approximately reversed pattern.
  Reversed = rev(obs)
)

## ----diagram-stats------------------------------------------------------------
diagram_stats(models, obs)

## ----solar-basic--------------------------------------------------------------
gg_solar(
  models,
  obs,
  label = TRUE,
  y.axis_end = 2
)

## ----solar-model-colours------------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "model",
  y.axis_end = 2
)

## ----solar-efficiency---------------------------------------------------------
gg_solar(
  models,
  obs,
  y.axis_end = 2
)

## ----solar-colour-options-----------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "correlation",
  y.axis_end = 2
)

gg_solar(
  models,
  obs,
  colour_by = "r2",
  y.axis_end = 2
)

## ----solar-axes---------------------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "model",
  x.axis_begin = -2,
  x.axis_end = 2,
  y.axis_end = 2,
  by = 0.5
)

## ----solar-no-reference-------------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "model",
  y.axis_end = 2,
  reference = FALSE
)

## ----target-basic-------------------------------------------------------------
gg_target(
  models,
  obs,
  label = TRUE
)

## ----target-model-colours-----------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "model"
)

## ----target-efficiency--------------------------------------------------------
gg_target(
  models,
  obs
)

## ----target-correlation-------------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "correlation"
)

## ----target-axes--------------------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "model",
  axis_begin = -2,
  axis_end = 2,
  by = 0.5
)

## ----target-no-reference------------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "model",
  reference = FALSE
)

## ----taylor-full--------------------------------------------------------------
gg_taylor(
  models,
  obs,
  label = TRUE
)

## ----taylor-half--------------------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE
)

## ----taylor-labels------------------------------------------------------------
gg_taylor(
  models,
  obs,
  label = TRUE,
  half = TRUE
)

## ----taylor-legend------------------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE
)

## ----taylor-no-rmsd-----------------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE,
  rmsd = FALSE
)

## ----taylor-rmsd-colour-------------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE,
  rmsd_colour = "grey40"
)

## ----taylor-rmsd-breaks-------------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE,
  rmsd_breaks = c(0.25, 0.5, 1, 1.5, 2)
)

## ----compare-biased-----------------------------------------------------------
diagram_stats(
  models[c("Good", "Biased")],
  obs
)

gg_taylor(
  models[c("Good", "Biased")],
  obs,
  label = TRUE,
  half = TRUE
)

## ----customise-title----------------------------------------------------------
p <- gg_solar(
  models,
  obs,
  colour_by = "model",
  y.axis_end = 2
)

p +
  ggplot2::labs(
    title = "Comparison of prediction models",
    subtitle = "Solar diagram"
  ) +
  ggplot2::theme_minimal()

## ----customise-legend---------------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "model",
  y.axis_end = 2
) +
  ggplot2::theme(
    legend.position = "bottom"
  )

## ----customise-taylor-colours-------------------------------------------------
gg_taylor(
  models,
  obs,
  legend = TRUE,
  half = TRUE
) +
  ggplot2::scale_colour_brewer(
    palette = "Dark2"
  ) +
  ggplot2::theme(
    legend.position = "bottom"
  )

## ----customise-target-colours-------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "model"
) +
  ggplot2::scale_fill_brewer(
    palette = "Dark2"
  ) +
  ggplot2::theme(
    legend.position = "bottom"
  )

## ----customise-target-labels--------------------------------------------------
gg_target(
  models,
  obs,
  colour_by = "model"
) +
  ggplot2::labs(
    x = "Signed SDE*",
    y = "ME*",
    title = "Target diagram"
  )

## ----customise-zoom-----------------------------------------------------------
gg_solar(
  models,
  obs,
  colour_by = "model",
  y.axis_end = 2
) +
  ggplot2::coord_fixed(
    xlim = c(-1.5, 1.5),
    ylim = c(0, 1.5)
  )

## ----customise-sizes----------------------------------------------------------
gg_solar(
  models,
  obs,
  label = TRUE,
  point_size = 5,
  label_size = 3.5,
  y.axis_end = 2
)

## ----customise-taylor-sizes---------------------------------------------------
gg_taylor(
  models,
  obs,
  label = TRUE,
  half = TRUE,
  point_size = 5,
  label_size = 3.5
)

