Skip to contents

Four complementary plot types for exploring simulated plant breeding trial data returned by simTrialData():

"trial"

A tiled field layout heatmap showing the Row x Column grid for each site, faceted by site. Tiles can be filled and/or labelled by any column in res$data. Use fill = NULL (default) to colour by replicate and inspect block structure; use fill = "yield" for a continuous yield surface; use fill = "Variety" or fill = "Treatment" to check randomisation and treatment strip layout.

"incidence"

A Variety x Site presence/absence tile grid showing which varieties appear at which sites. Each variety label is annotated with its site count [n]; each site label is annotated with its variety count [n]. Particularly useful for visualising unbalanced designs generated with incidence = "unbalanced".

"correlation"

A full heatmap of the true genetic correlation matrix cov2cor(params$G). A diverging RdBu palette centred at zero reveals between-environment genetic correlations. Correlation values are printed when the matrix has 15 or fewer groups.

"blup"

A heatmap of the true genetic BLUPs (params$g_arr) with varieties on the y-axis and environments (or Treatment x Site groups) on the x-axis. The diverging RdBu scale centred at zero reveals the genotype-by-environment interaction (GEI) structure embedded in the simulated data.

Usage

plot_simTrialData(
  res,
  type = c("trial", "incidence", "correlation", "blup"),
  fill = NULL,
  label = NULL,
  sites = NULL,
  sort = TRUE,
  ncol = NULL,
  theme = ggplot2::theme_bw(),
  return_data = FALSE,
  ...
)

Arguments

res

List returned by simTrialData().

type

Plot type. One of "trial" (default), "incidence", "correlation", or "blup".

fill

"trial" type only. Name of a column in res$data to map to the tile fill colour, or NULL (default) to colour by replicate (Rep). Numeric columns use a continuous viridis scale; character or factor columns use a discrete palette.

label

"trial" type only. Name of a column in res$data to overlay as text on each plot cell, or NULL (default) for no labels. Works best with short values such as variety abbreviations or replicate numbers; "yield" will show rounded values.

sites

Character vector of site names to include, or NULL (default) for all sites. Applied to "trial" and "blup" types. For "blup" in a multi-treatment design, pass the full TSite labels (e.g. "T0-Env01"); partial matching by substring is used as a fallback.

sort

Logical. When TRUE (default):

  • "incidence": varieties ordered top-to-bottom by decreasing site count (most-connected variety at top).

  • "blup": varieties ordered top-to-bottom by decreasing mean BLUP across all groups (highest overall performer at top).

No effect for "trial" or "correlation".

ncol

Integer or NULL. "trial" type only. Number of columns passed to facet_wrap. NULL (default) lets ggplot2 choose automatically.

theme

A ggplot2 theme object applied to all plots. Default theme_bw().

return_data

Logical. If TRUE, returns a named list with elements $plot (the ggplot object) and $data (the data frame used to build the plot). Default FALSE.

...

Currently unused.

Value

A ggplot object, or a named list with elements $plot and $data when return_data = TRUE.

See also

Examples

if (FALSE) { # \dontrun{
out <- simTrialData(nvar = 20, nsite = 4, seed = 1, verbose = FALSE)

# Field layout coloured by replicate (default)
plot_simTrialData(out)

# Yield heatmap with variety labels
plot_simTrialData(out, type = "trial", fill = "yield", label = "Variety")

# Rep colouring with treatment strips visible in column layout
out_sp <- simTrialData(nvar = 10, nsite = 3,
                       treatments = c("T0", "T1", "T2"),
                       seed = 5, verbose = FALSE)
plot_simTrialData(out_sp, type = "trial", fill = "Treatment")

# Incidence for an unbalanced design
out2 <- simTrialData(nvar = 30, nsite = 8, incidence = "unbalanced",
                     seed = 42, verbose = FALSE)
plot_simTrialData(out2, type = "incidence")

# True genetic correlation matrix
plot_simTrialData(out, type = "correlation")

# True BLUP heatmap revealing GEI structure
plot_simTrialData(out, type = "blup")

# Return data for custom modifications
res <- plot_simTrialData(out, type = "blup", return_data = TRUE)
res$plot + ggplot2::ggtitle("My custom title")
head(res$data)
} # }