Skip to contents

Produces one of three ggplot2 visualisations from a randomRegress() result object. All plot types return a ggplot object that can be further customised with the standard + operator.

Usage

plot_randomRegress(
  res,
  type = c("regress", "quadrant", "gmat"),
  treatments = NULL,
  highlight = "default",
  centre = FALSE,
  cond_x = 1L,
  theme = ggplot2::theme_bw(),
  return_data = FALSE,
  ...
)

Arguments

res

A list returned by randomRegress().

type

Character string selecting the plot type. One of "regress" (default), "quadrant", or "gmat".

treatments

Character vector restricting which conditioned treatments are included in the plot. NULL (default) includes all conditioned treatments. Ignored for type = "gmat".

highlight

Controls variety annotation for "regress" and "quadrant" plots. One of:

"default"

Automatically selects 6 varieties (3 top-right, 3 bottom-left) using the polar-angle algorithm described in Details.

character vector

Highlight exactly the named varieties.

NULL

No highlighting; all points drawn in a single colour.

Default is "default". Ignored for type = "gmat".

centre

Logical. If FALSE (default), BLUPs are plotted on their natural scale (already centred near zero by the mixed model). If TRUE, the within-site mean of the unconditional treatment is added back to the x-axis values, placing BLUPs on an approximate absolute yield scale. For true ASReml BLUPs the site mean is effectively zero so the change is minimal; this option is mainly useful when BLUPs have been computed from treatment means (e.g. in the demo). Ignored for type = "gmat".

cond_x

Positive integer or integer vector (default 1L). Selects which member of the conditioning set \(A_j\) is placed on the x-axis of the "regress" plot for each conditioned-treatment panel. A scalar is recycled across all panels; a vector of the same length as the number of conditioned treatments plotted sets each panel independently. For example, with three conditioned treatments under partial conditioning:

  • cond_x = 1L (default) — first member of \(A_j\) for every panel, e.g. c(1, 1, 1).

  • cond_x = 2L — second member for every panel.

  • cond_x = c(2, 1, 2) — panel-specific selection.

An index that exceeds \(|A_j|\) for a given panel triggers a warning and falls back to 1. Has no effect when \(|A_j| = 1\) (e.g. type = "baseline"). Ignored for type = "quadrant" and "gmat".

theme

A complete ggplot2 theme object. Default ggplot2::theme_bw().

return_data

Logical. If TRUE returns the tidy data frame used to build the plot rather than the plot itself. Default FALSE.

...

Additional arguments passed to the background geom_point() call (e.g. size, alpha, shape). Not used for "gmat".

Value

A ggplot object (when return_data = FALSE) or a data.frame (when return_data = TRUE).

Details

The three type options are:

"regress"

Grid of scatter plots faceted by BLUP pair (rows) and site (columns). Each panel plots the raw conditioned-treatment BLUPs (y) against the conditioning-treatment BLUPs (x) for one site x one treatment pair. A dotted random regression line with the site-specific beta slope passes through the origin. The site-specific \(\hat{\beta}\) is annotated in the top-left corner of each panel.

"quadrant"

Grid of scatter plots faceted by BLUP pair (rows) and site (columns). Each panel plots responsiveness BLUPs (y) against the conditioning treatment BLUPs (x = efficiency) for one site x one treatment pair. Dotted zero reference lines on both axes divide each panel into four quadrants.

"gmat"

Heatmap of the G-matrix converted to a correlation matrix via stats::cov2cor(). Fill uses a diverging palette centred at zero.

Variety highlighting (type = "regress" and "quadrant" only): By default, up to six varieties are identified and annotated across all panels — up to three from the top-right quadrant of the efficiency x responsiveness space (above average on both axes, shown in orange) and up to three from the bottom-left quadrant (below average on both axes, shown in blue). Within each quadrant only varieties whose distance from the origin exceeds the within-quadrant median are considered, and the final selection is the most extreme of those candidates ordered by decreasing distance. The same varieties are consistently annotated across all site and treatment-pair panels.

Examples

if (FALSE) { # \dontrun{
res <- randomRegress(model, levs = c("N0", "N1", "N2"))

# Regression plot with default 6 highlighted varieties
plot_randomRegress(res)

# Quadrant plot with user-specified highlights
plot_randomRegress(res, type = "quadrant",
                  highlight = c("Var01", "Var15", "Var22"))

# Suppress highlighting
plot_randomRegress(res, type = "quadrant", highlight = NULL)

# G-matrix correlation heatmap
plot_randomRegress(res, type = "gmat")

# Retrieve the tidy data frame
df <- plot_randomRegress(res, type = "quadrant", return_data = TRUE)

# Partial conditioning — default (first conditioning treatment on x)
res_part <- randomRegress(model, term = "us(TSite):Variety",
                          levs = c("N0","N1","N2"), type = "partial")
plot_randomRegress(res_part, type = "regress")              # cond_x = 1L

# Show the second conditioning treatment on the x-axis for all panels
plot_randomRegress(res_part, type = "regress", cond_x = 2L)

# Mixed: second for panels 1 & 3, first for panel 2
plot_randomRegress(res_part, type = "regress", cond_x = c(2L, 1L, 2L))
} # }