Last updated: 2026-08-03
Checks: 6 1
Knit directory:
nonlinear-ge-interaction-shap/
This reproducible R Markdown analysis was created with workflowr (version 1.7.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of
the R Markdown file created these results, you’ll want to first commit
it to the Git repo. If you’re still working on the analysis, you can
ignore this warning. When you’re finished, you can run
wflow_publish to commit the R Markdown file and build the
HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20260713) was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version d67ab40. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish or
wflow_git_commit). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
Ignored: .Rproj.user/
Ignored: code/Codigo_SHAP_GE_10_07_23.txt
Ignored: code/Codigo_SHAP_GE_15_07_23.txt
Ignored: code/Script_15-07.txt
Ignored: data/Artigo_Completo.pdf
Ignored: data/Artigos/
Ignored: data/Complex and Non-Linear Modeling of Genotype × Environment Interaction via Tree-Based Learning Algorithms and Shapley Decomposition.docx
Ignored: data/Complex and Non-Linear Modeling of Genotype × Environment Interaction via Tree-Based Learning Algorithms and Shapley Decomposition_WGC.docx
Ignored: data/Manuscript_Agriculture_MN_03_08_26 (1).docx
Ignored: data/Manuscript_Agriculture_MN_03_08_26.docx
Ignored: data/Manuscript_MN_NE_ACCN(Inglês) (1).docx
Ignored: data/Manuscript_MN_NE_ACCN.docx
Ignored: data/Proposta_Edital_Universal.docx
Ignored: data/Proposta_Edital_Universal_WGC.docx
Untracked files:
Untracked: data/script_03-08.txt
Untracked: update_analysis_add_shap_loess.R
Unstaged changes:
Modified: analysis/analysis.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were
made to the R Markdown (analysis/analysis.Rmd) and HTML
(docs/analysis.html) files. If you’ve configured a remote
Git repository (see ?wflow_git_remote), click on the
hyperlinks in the table below to view the files as they were in that
past version.
| File | Version | Author | Date | Message |
|---|---|---|---|---|
| html | d67ab40 | WevertonGomesCosta | 2026-07-29 | Rebuild site with updated authors and affiliations |
| Rmd | 0363155 | GitHub | 2026-07-29 | Update manuscript authors and affiliations |
| html | 27459d8 | WevertonGomesCosta | 2026-07-15 | analysis foi adaptada à nova versão do script fornecido |
| Rmd | 3dc445e | Weverton Gomes da Costa | 2026-07-15 | Update analysis for revised five-figure workflow |
| html | 5dde84b | WevertonGomesCosta | 2026-07-15 | Rebuild analysis with committed source |
| Rmd | 458c002 | WevertonGomesCosta | 2026-07-15 | update analysis.Rmd and .html |
| html | 458c002 | WevertonGomesCosta | 2026-07-15 | update analysis.Rmd and .html |
| html | b5291bd | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 7c01fbf | WevertonGomesCosta | 2026-07-15 | Update rank dynamics description for SHAP SSI |
| html | 96b9761 | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 42404fc | WevertonGomesCosta | 2026-07-15 | Update ranking dynamics and correlations for SHAP SSI |
| html | e34e85f | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 531f928 | WevertonGomesCosta | 2026-07-15 | Add SHAP-based simultaneous selection index |
| html | 59212d0 | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 70b332d | WevertonGomesCosta | 2026-07-15 | Standardize AMMI and SHAP genotype colors |
| html | 88f6ef4 | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 2f739c5 | WevertonGomesCosta | 2026-07-15 | Restore environmental index calculation |
| html | 272d87a | WevertonGomesCosta | 2026-07-15 | Build site. |
| Rmd | 4c77fe8 | WevertonGomesCosta | 2026-07-15 | Update phenotypic performance figure for revised manuscript |
| html | 0105fbd | WevertonGomesCosta | 2026-07-14 | Build site. |
| Rmd | 84a260a | WevertonGomesCosta | 2026-07-14 | Disable repeated LOEO fitting and load validated results |
| html | abd35e1 | WevertonGomesCosta | 2026-07-14 | Build site. |
| Rmd | 00803c4 | WevertonGomesCosta | 2026-07-14 | Load validated results for computationally intensive analyses |
| html | 83325f9 | WevertonGomesCosta | 2026-07-14 | Build site. |
| Rmd | e9401c2 | WevertonGomesCosta | 2026-07-14 | Use full-width figures and tables |
| html | 86b4bbc | WevertonGomesCosta | 2026-07-14 | Build site. |
| Rmd | 20f6446 | WevertonGomesCosta | 2026-07-14 | Update project pages, authorship, contacts, and citation |
| html | 02fb7fb | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | d7f6a52 | WevertonGomesCosta | 2026-07-13 | Complete genotype ranking and stability analyses |
| html | 7a46ba1 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | f059a2a | WevertonGomesCosta | 2026-07-13 | Add stability indices and genotype rankings |
| html | 03dc0c0 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | d4ef886 | WevertonGomesCosta | 2026-07-13 | Add joint AMMI and SHAP representation |
| html | f321462 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | df4cac4 | WevertonGomesCosta | 2026-07-13 | Add AMMI decomposition and interaction biplot |
| html | 95e3343 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | df27105 | WevertonGomesCosta | 2026-07-13 | Fix SHAP profile plot margin namespace |
| html | b59cfdd | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | 236dcfd | WevertonGomesCosta | 2026-07-13 | Add environmental index and Random Forest validation |
| html | 029bb27 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | 3bca313 | WevertonGomesCosta | 2026-07-13 | Add data preparation and phenotypic performance analysis |
| html | 9f70394 | WevertonGomesCosta | 2026-07-13 | Build site. |
| Rmd | 6f375a8 | WevertonGomesCosta | 2026-07-13 | Add initial reproducible analysis page |
This page presents the complete reproducible analytical workflow associated with the study “Non-Linear Modeling of Genotype × Environment Interaction via Tree-Based Learning Algorithms and Shapley Decomposition.”
The workflow combines phenotypic evaluation, Random Forest modeling, Shapley Additive Explanations, SHAP dependence visualization, AMMI decomposition, stability indices, genotype ranking, and rank correlation.
All analytical code is presented directly in this R Markdown document and follows the order required to reproduce the analysis.
The following packages are used for data manipulation, graphical visualization, Random Forest modeling, SHAP decomposition, faceted scale control, genotype-rank visualization, and rank-correlation analysis.
library(ggplot2)
library(dplyr)
library(tidyr)
library(randomForest)
library(DALEX)
library(iBreakDown)
library(pals)
library(ggh4x)
library(ggcorrplot)
The maize multi-environment trial data set is stored as a
tab-delimited text file in the data directory.
maize <- read.table(
"data/maize.txt",
h = TRUE
)
head(maize)
ENV GEN REP GY
1 1 1 1 3699.7
2 1 1 2 2947.9
3 1 1 3 3745.3
4 1 1 4 4093.3
5 1 2 1 3801.2
6 1 2 2 1631.4
The original replicate-level observations are summarized by genotype and environment. The resulting data frame contains the mean grain yield for each genotype-by-environment combination.
df_ml <- maize %>%
group_by(GEN, ENV) %>%
summarise(
GY = mean(GY, na.rm = TRUE),
.groups = "drop"
)
df_ml$ENV <- as.factor(df_ml$ENV)
df_ml$GEN <- as.factor(df_ml$GEN)
The leave-one-environment-out design uses each environment once as the validation environment. The diagonal cells identify the environment excluded in each iteration, while the remaining environments are retained for model fitting.
loeo_scheme <- tidyr::expand_grid(
Iteration_number = seq_len(20),
Environment_number = seq_len(20)
) %>%
mutate(
Value = as.numeric(
Iteration_number == Environment_number
),
Iteration = factor(
paste0("Iter", Iteration_number),
levels = rev(
paste0("Iter", seq_len(20))
)
),
Environment = factor(
paste0("Env", Environment_number),
levels = paste0(
"Env",
seq_len(20)
)
)
)
figure_1 <- ggplot(
loeo_scheme,
aes(
x = Environment,
y = Iteration,
fill = Value
)
) +
geom_tile(
color = "white",
linewidth = 0.1,
alpha = 0.5
) +
scale_fill_gradient(
low = "#4ADC36",
high = "#DB241F",
guide = "none"
) +
labs(
x = "Environments",
y = "Iterations"
) +
theme(
panel.background = element_blank(),
panel.grid = element_blank(),
legend.position = "none",
plot.margin = ggplot2::margin(
t = 2,
r = 0,
b = 0,
l = 0
),
axis.line = element_blank(),
axis.text.y = element_text(
size = 7,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 7,
angle = 90,
vjust = 0.5,
hjust = 0.5,
color = "black",
family = "serif"
),
axis.title.y = element_text(
size = 12,
color = "black",
family = "serif"
),
axis.title.x = element_text(
size = 10,
color = "black",
family = "serif"
),
axis.ticks = element_blank()
)
print(figure_1)

| Version | Author | Date |
|---|---|---|
| 27459d8 | WevertonGomesCosta | 2026-07-15 |
The distribution of mean grain yield is represented in two vertically arranged panels. Panel A displays the environmental distributions, and Panel B displays the genotype distributions. Every jittered point represents one genotype-by-environment mean.
The boxplot outliers are not displayed separately because all genotype-by-environment means are already represented by the jittered points.
phenotypic_plot_data <- bind_rows(
df_ml %>%
transmute(
facet = "A",
Category = factor(
as.character(ENV),
levels = as.character(seq_len(20))
),
GY = GY
),
df_ml %>%
transmute(
facet = "B",
Category = factor(
as.character(GEN),
levels = as.character(seq_len(20))
),
GY = GY
)
)
phenotypic_titles <- data.frame(
facet = c("A", "B"),
Category = factor(
c("10", "5"),
levels = as.character(seq_len(20))
),
x_title = c(
"Environments",
"Genotypes"
)
)
figure_2 <- ggplot(
phenotypic_plot_data,
aes(
x = Category,
y = GY,
fill = Category
)
) +
facet_wrap(
~facet,
scales = "free",
ncol = 1
) +
geom_boxplot(
alpha = 0.75,
outlier.shape = NA,
linewidth = 0.4
) +
geom_jitter(
width = 0.15,
alpha = 0.4,
color = "black",
size = 1.2
) +
geom_text(
data = phenotypic_titles,
aes(
x = Category,
y = -Inf,
label = x_title
),
inherit.aes = FALSE,
vjust = 3,
size = 3.5,
family = "serif",
color = "black"
) +
scale_fill_manual(
values = stats::setNames(
as.vector(
pals::glasbey(20)
),
as.character(seq_len(20))
)
) +
coord_cartesian(
clip = "off"
) +
labs(
x = "",
y = expression(
paste(
"Grain Yield (GY) in kg ",
ha^-1
)
)
) +
theme(
strip.background = element_blank(),
panel.background = element_rect(
color = "black",
fill = "white"
),
panel.grid = element_blank(),
legend.position = "none",
plot.margin = ggplot2::margin(
t = 2,
r = 0,
b = 8,
l = 0
),
axis.line.x = element_blank(),
axis.line.y = element_line(
color = "black"
),
axis.text.y = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.title.y = element_text(
size = 12,
color = "black",
family = "serif"
),
axis.title.x = element_blank(),
axis.ticks = element_blank(),
strip.text = element_text(
hjust = 0,
size = 9,
family = "serif",
color = "black"
)
)
print(figure_2)

The environmental index is calculated as the mean grain yield of all genotypes evaluated within each environment. This continuous variable represents the productive potential of each environment.
env_indices <- df_ml %>%
group_by(ENV) %>%
summarise(
ENV_INDEX = mean(
GY,
na.rm = TRUE
),
.groups = "drop"
)
df_ml <- df_ml %>%
left_join(
env_indices,
by = "ENV"
)
head(env_indices)
# A tibble: 6 × 2
ENV ENV_INDEX
<fct> <dbl>
1 1 3613.
2 2 4209.
3 3 5105.
4 4 5230.
5 5 4955.
6 6 6305.
The Random Forest model is evaluated through leave-one-environment-out cross-validation. At each iteration, one environment is reserved for prediction, while the remaining environments are used for model fitting.
set.seed(42)
ambientes <- unique(df_ml$ENV)
predicoes_cv <- data.frame()
cat("Starting leave-one-environment-out cross-validation...\n")
for (env_teste in ambientes) {
dados_treino <- df_ml %>%
filter(
ENV != env_teste
)
dados_teste <- df_ml %>%
filter(
ENV == env_teste
)
rf_fold <- randomForest(
GY ~ GEN + ENV_INDEX,
data = dados_treino,
ntree = 500
)
dados_teste$Pred_GY <- predict(
rf_fold,
newdata = dados_teste
)
predicoes_cv <- bind_rows(
predicoes_cv,
dados_teste
)
}
predicoes_cv <- predicoes_cv %>%
arrange(
ENV,
GEN
)
validation_file <- "output/random_forest_loeo_predictions.rds"
dir.create(
dirname(validation_file),
recursive = TRUE,
showWarnings = FALSE
)
saveRDS(
predicoes_cv,
validation_file
)
Predictive performance is summarized using the cross-validated coefficient of determination, the Pearson correlation between observed and predicted grain yield, and the root mean squared error.
ss_res <- sum(
(predicoes_cv$GY - predicoes_cv$Pred_GY)^2
)
ss_tot <- sum(
(predicoes_cv$GY - mean(predicoes_cv$GY))^2
)
r2_cv <- 1 - (ss_res / ss_tot)
rmse_cv <- sqrt(
mean(
(predicoes_cv$GY - predicoes_cv$Pred_GY)^2
)
)
accuracy_r <- cor(
predicoes_cv$GY,
predicoes_cv$Pred_GY
)
cat(
"\n=== LEAVE-ONE-ENVIRONMENT-OUT VALIDATION METRICS ===\n"
)
=== LEAVE-ONE-ENVIRONMENT-OUT VALIDATION METRICS ===
cat(
"Predictive capacity (cross-validated R²): ",
round(r2_cv * 100, 2),
"%\n"
)
Predictive capacity (cross-validated R²): 71.94 %
cat(
"Predictive accuracy (r): ",
round(accuracy_r, 2),
"\n"
)
Predictive accuracy (r): 0.85
cat(
"Cross-validation RMSE: ",
round(rmse_cv, 2),
" kg ha-1\n"
)
Cross-validation RMSE: 717.02 kg ha-1
The final Random Forest model is fitted using the complete analytical data set. Grain yield is modeled as a function of genotype and the continuous environmental index.
set.seed(42)
rf_model <- randomForest(
GY ~ GEN + ENV_INDEX,
data = df_ml,
ntree = 500
)
The Random Forest model is connected to the DALEX framework using the genotype and environmental-index predictors. The response variable supplied to the explainer is the observed mean grain yield.
explainer_rf <- explain(
model = rf_model,
data = df_ml[
,
c(
"GEN",
"ENV_INDEX"
)
],
y = df_ml$GY,
label = "Random Forest GxE (Continuous)"
)
SHAP contributions are calculated for every genotype-by-environment observation. For each observation, the mean contribution associated with genotype and environmental index is extracted from the SHAP decomposition.
set.seed(42)
shap_list <- vector(
mode = "list",
length = nrow(df_ml)
)
cat("Starting SHAP contribution calculation...\n")
for (i in seq_len(nrow(df_ml))) {
obs <- df_ml[
i,
c(
"GEN",
"ENV_INDEX"
)
]
shap_obs <- predict_parts(
explainer = explainer_rf,
new_observation = obs,
type = "shap",
B = 25
)
val_gen <- shap_obs %>%
filter(
variable_name == "GEN"
) %>%
summarise(
SHAP_GEN = mean(contribution),
.groups = "drop"
) %>%
pull(SHAP_GEN)
val_env <- shap_obs %>%
filter(
variable_name == "ENV_INDEX"
) %>%
summarise(
SHAP_ENV = mean(contribution),
.groups = "drop"
) %>%
pull(SHAP_ENV)
shap_list[[i]] <- data.frame(
SHAP_GEN = val_gen,
SHAP_ENV = val_env
)
}
df_shap_final <- bind_rows(
shap_list
)
df_results <- bind_cols(
df_ml,
df_shap_final
) %>%
arrange(
ENV,
GEN
)
shap_file <- "output/shap_results.rds"
dir.create(
dirname(shap_file),
recursive = TRUE,
showWarnings = FALSE
)
saveRDS(
df_results,
shap_file
)
head(df_results)
# A tibble: 6 × 6
GEN ENV GY ENV_INDEX SHAP_GEN SHAP_ENV
<fct> <fct> <dbl> <dbl> <dbl> <dbl>
1 1 1 3622. 3613. -131. -1079.
2 2 1 3426. 3613. -101. -1172.
3 3 1 3446. 3613. -12.1 -1161.
4 4 1 3720. 3613. 147. -1555.
5 5 1 3165. 3613. -27.5 -1349.
6 6 1 4116. 3613. 321. -1313.
The genotype-by-environment interaction effects are obtained after removing the genotype and environment main effects from the mean grain-yield observations.
grand_mean <- mean(
df_results$GY,
na.rm = TRUE
)
env_effects <- df_results %>%
group_by(ENV) %>%
summarise(
m_env = mean(
GY,
na.rm = TRUE
),
.groups = "drop"
)
gen_effects <- df_results %>%
group_by(GEN) %>%
summarise(
m_gen = mean(
GY,
na.rm = TRUE
),
.groups = "drop"
)
df_int <- df_results %>%
left_join(
env_effects,
by = "ENV"
) %>%
left_join(
gen_effects,
by = "GEN"
) %>%
mutate(
GE_effect = GY - m_env - m_gen + grand_mean
)
mat_int <- df_int %>%
select(
GEN,
ENV,
GE_effect
) %>%
pivot_wider(
names_from = ENV,
values_from = GE_effect
) %>%
tibble::column_to_rownames(
"GEN"
) %>%
as.matrix()
Singular value decomposition is applied to the genotype-by-environment interaction matrix. The squared singular values are used to calculate the percentage of interaction variation represented by each component.
svd_ammi <- svd(
mat_int
)
lambda <- svd_ammi$d
var_explained <- (
lambda^2 / sum(lambda^2)
) * 100
ipca1_pct <- round(
var_explained[1],
2
)
ipca2_pct <- round(
var_explained[2],
2
)
data.frame(
Component = paste0(
"IPCA",
seq_along(var_explained)
),
Explained_variation = round(
var_explained,
2
)
)
Component Explained_variation
1 IPCA1 56.20
2 IPCA2 15.10
3 IPCA3 10.44
4 IPCA4 8.62
5 IPCA5 4.95
6 IPCA6 2.76
7 IPCA7 1.01
8 IPCA8 0.92
9 IPCA9 0.00
The scores of the first two interaction principal components are obtained separately for genotypes and environments.
scores_gen <- as.data.frame(
svd_ammi$u[, 1:2] %*%
diag(
sqrt(lambda[1:2])
)
)
colnames(scores_gen) <- c(
"IPCA1",
"IPCA2"
)
scores_gen$GEN <- as.factor(
rownames(mat_int)
)
scores_env <- as.data.frame(
svd_ammi$v[, 1:2] %*%
diag(
sqrt(lambda[1:2])
)
)
colnames(scores_env) <- c(
"IPCA1",
"IPCA2"
)
scores_env$ENV <- as.factor(
colnames(mat_int)
)
The first panel represents the genotype scores and environmental vectors for the first two AMMI interaction principal components. The second panel represents genotype-specific SHAP contributions across environments.
ammi_gen_plot_data <- scores_gen %>%
mutate(
facet = "A"
)
ammi_env_plot_data <- scores_env %>%
mutate(
facet = "A"
)
shap_plot_data <- df_results %>%
transmute(
GEN = as.factor(GEN),
ENV = as.numeric(
as.character(ENV)
),
SHAP_GEN = SHAP_GEN,
facet = "B"
)
figure_3_titles <- data.frame(
facet = c(
"A",
"B"
),
x_title = c(
paste0(
"IPCA1 (",
ipca1_pct,
"%)"
),
"Environments"
),
y_title = c(
paste0(
"IPCA2 (",
ipca2_pct,
"%)"
),
"Genotype SHAP Value (G × E Effect) in kg ha⁻¹"
),
x = c(
-7,
10
),
y = c(
-7,
-100
)
)
figure_3 <- ggplot() +
facet_wrap(
~facet,
scales = "free",
ncol = 1
) +
coord_cartesian(
clip = "off"
) +
geom_vline(
data = data.frame(
facet = "A",
x = 0
),
aes(
xintercept = x
),
linetype = "dashed",
color = "gray60",
linewidth = 0.4
) +
geom_hline(
data = data.frame(
facet = c(
"A",
"B"
),
y = 0
),
aes(
yintercept = y
),
linetype = "dashed",
color = "gray60",
linewidth = 0.4
) +
geom_segment(
data = ammi_env_plot_data,
aes(
x = 0,
y = 0,
xend = IPCA1,
yend = IPCA2
),
arrow = arrow(
length = grid::unit(
0.18,
"cm"
)
),
color = "gray30",
alpha = 0.6,
linewidth = 0.5
) +
geom_text(
data = ammi_env_plot_data,
aes(
x = IPCA1,
y = IPCA2,
label = ENV
),
vjust = 1.4,
family = "serif",
color = "gray20",
size = 3
) +
geom_point(
data = ammi_gen_plot_data,
aes(
x = IPCA1,
y = IPCA2,
color = GEN
),
size = 3.5,
alpha = 0.9
) +
geom_text(
data = ammi_gen_plot_data,
aes(
x = IPCA1,
y = IPCA2,
label = GEN
),
vjust = -1.2,
family = "serif",
fontface = "bold",
size = 3.5,
show.legend = FALSE
) +
geom_line(
data = shap_plot_data,
aes(
x = ENV,
y = SHAP_GEN,
group = GEN,
color = GEN
),
linewidth = 0.5
) +
geom_point(
data = shap_plot_data,
aes(
x = ENV,
y = SHAP_GEN,
group = GEN,
color = GEN
),
size = 1
) +
geom_text(
data = figure_3_titles,
aes(
x = x,
y = -Inf,
label = x_title
),
inherit.aes = FALSE,
vjust = 4.5,
size = 3,
family = "serif",
color = "black"
) +
geom_text(
data = figure_3_titles,
aes(
x = -Inf,
y = y,
label = y_title
),
inherit.aes = FALSE,
vjust = -5,
size = 3,
family = "serif",
color = "black",
angle = 90
) +
scale_color_manual(
values = as.vector(
pals::glasbey(9)
)
) +
labs(
x = "",
y = "",
color = "Genotype"
) +
theme(
strip.background = element_blank(),
panel.background = element_rect(
color = "black",
fill = "white"
),
panel.grid = element_blank(),
legend.position = "bottom",
plot.margin = ggplot2::margin(
t = 2,
r = 0,
b = 0,
l = 0
),
legend.text = element_text(
size = 10,
family = "serif"
),
legend.title = element_text(
size = 10,
family = "serif",
vjust = 0.5
),
axis.line.x = element_blank(),
axis.line.y = element_line(
color = "black"
),
axis.text.y = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.title = element_blank(),
axis.ticks = element_blank(),
legend.key = element_blank(),
strip.text = element_text(
hjust = 0,
size = 9,
family = "serif",
color = "black"
)
) +
ggh4x::facetted_pos_scales(
x = list(
facet == "A" ~ scale_x_continuous(
breaks = seq(
-50,
50,
20
)
),
facet == "B" ~ scale_x_continuous(
breaks = seq_len(20)
)
),
y = list(
facet == "A" ~ scale_y_continuous(
limits = c(
-40,
30
)
),
facet == "B" ~ scale_y_continuous()
)
)
print(figure_3)

The SHAP dependence plot relates the genotype-specific SHAP contribution to the environmental index. Points represent genotype-by-environment observations, while genotype-specific LOESS curves summarize nonlinear response patterns across the environmental gradient.
shap_dependence_data <- df_results %>%
mutate(
GEN = as.factor(GEN)
)
figure_4 <- ggplot(
shap_dependence_data,
aes(
x = ENV_INDEX,
y = SHAP_GEN,
color = GEN,
group = GEN
)
) +
geom_hline(
yintercept = 0,
linetype = "dashed",
color = "gray60",
linewidth = 0.4
) +
geom_point(
size = 1.8,
alpha = 0.4
) +
geom_smooth(
method = "loess",
formula = y ~ x,
se = FALSE,
linewidth = 1.2,
alpha = 0.9
) +
scale_color_manual(
values = as.vector(
pals::glasbey(9)
)
) +
labs(
x = "Environmental Index",
y = expression(
paste(
"Genotype SHAP Value (G × E Effect) in kg ",
ha^-1
)
),
color = "Genotype"
) +
theme_classic(
base_size = 12
) +
theme(
panel.background = element_rect(
color = "black",
fill = "white"
),
panel.grid = element_blank(),
legend.position = "right",
plot.margin = ggplot2::margin(
t = 0,
r = 0,
b = 0,
l = 0
),
legend.text = element_text(
size = 8,
family = "serif"
),
legend.title = element_text(
size = 9,
family = "serif",
vjust = 0.5
),
axis.line.x = element_blank(),
axis.line.y = element_line(
color = "black"
),
axis.text.y = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.title.y = element_text(
size = 11,
color = "black",
family = "serif"
),
axis.title.x = element_text(
size = 11,
color = "black",
family = "serif"
),
axis.ticks = element_blank(),
legend.key = element_blank()
)
print(figure_4)

The AMMI Stability Value combines the scores of the first two interaction principal components. Lower ASV values indicate greater stability according to the AMMI representation.
peso_asv <- var_explained[1] /
var_explained[2]
asv_gen <- scores_gen %>%
mutate(
ASV = sqrt(
((peso_asv * IPCA1)^2) +
(IPCA2^2)
)
) %>%
select(
GEN,
ASV
)
asv_gen
GEN ASV
1 1 109.89080
2 2 73.04897
3 3 47.86631
4 4 147.49554
5 5 83.25008
6 6 78.58688
7 7 39.96620
8 8 142.48535
9 9 92.81560
The mean genotype SHAP contribution represents the average contribution of each genotype across environments. The standard deviation of the genotype SHAP contributions represents the variation of this contribution across environments.
tab_shap <- df_results %>%
group_by(GEN) %>%
summarise(
Media_GY = mean(GY),
SHAP_Medio = mean(SHAP_GEN),
SHAP_SD = sd(SHAP_GEN),
.groups = "drop"
)
tab_shap
# A tibble: 9 × 4
GEN Media_GY SHAP_Medio SHAP_SD
<fct> <dbl> <dbl> <dbl>
1 1 4617. -250. 102.
2 2 4603. -252. 102.
3 3 4823. -43.0 70.3
4 4 5218. 344. 198.
5 5 5247. 376. 205.
6 6 5330. 435. 113.
7 7 4672. -187. 141.
8 8 4283. -496. 253.
9 9 4930. 70.7 88.3
The classical Simultaneous Selection Index combines the grain-yield ranking and the AMMI Stability Value ranking through their rank sum.
The SHAP-based Simultaneous Selection Index combines the mean genotype SHAP contribution and SHAP stability after min–max normalization to a common scale from 0 to 100. Higher normalized values indicate more favorable performance. The index assigns a weight of 60% to mean SHAP contribution and 40% to SHAP stability.
theta1 <- 60
theta2 <- 40
dados_resultado <- left_join(
tab_shap,
asv_gen,
by = "GEN"
) %>%
mutate(
Rank_Prod = rank(
-Media_GY,
ties.method = "first"
),
Rank_ASV = rank(
ASV,
ties.method = "first"
),
Rank_SHAP_Eff = rank(
-SHAP_Medio,
ties.method = "first"
),
Rank_SHAP_Stb = rank(
SHAP_SD,
ties.method = "first"
),
SHAP_Medio_scaled = 100 * (
SHAP_Medio - min(SHAP_Medio)
) / (
max(SHAP_Medio) - min(SHAP_Medio)
),
SHAP_SD_scaled = 100 * (
max(SHAP_SD) - SHAP_SD
) / (
max(SHAP_SD) - min(SHAP_SD)
),
SHAP_SSI = (
SHAP_Medio_scaled * theta1 +
SHAP_SD_scaled * theta2
) / (
theta1 + theta2
),
Rank_SHAP_SSI = rank(
-SHAP_SSI,
ties.method = "first"
),
Rank_SSI = rank(
Rank_Prod + Rank_ASV,
ties.method = "first"
)
) %>%
arrange(
Rank_Prod
)
Genotypes are compared according to grain yield, AMMI stability, the classical simultaneous selection index, mean SHAP contribution, SHAP stability, and the SHAP-based simultaneous selection index. In every ranking, position 1 represents the preferred genotype according to the corresponding criterion.
print(
dados_resultado
)
# A tibble: 9 × 14
GEN Media_GY SHAP_Medio SHAP_SD ASV Rank_Prod Rank_ASV Rank_SHAP_Eff
<fct> <dbl> <dbl> <dbl> <dbl> <int> <int> <int>
1 6 5330. 435. 113. 78.6 1 4 1
2 5 5247. 376. 205. 83.3 2 5 2
3 4 5218. 344. 198. 147. 3 9 3
4 9 4930. 70.7 88.3 92.8 4 6 4
5 3 4823. -43.0 70.3 47.9 5 2 5
6 7 4672. -187. 141. 40.0 6 1 6
7 1 4617. -250. 102. 110. 7 7 7
8 2 4603. -252. 102. 73.0 8 3 8
9 8 4283. -496. 253. 142. 9 8 9
# ℹ 6 more variables: Rank_SHAP_Stb <int>, SHAP_Medio_scaled <dbl>,
# SHAP_SD_scaled <dbl>, SHAP_SSI <dbl>, Rank_SHAP_SSI <int>, Rank_SSI <int>
The rank-dynamics plot represents how the relative position of each genotype changes across grain yield, AMMI stability, classical simultaneous selection, SHAP stability, SHAP-based simultaneous selection, and mean SHAP effect. Rank 1 represents the preferred position under every criterion.
dados_long <- dados_resultado %>%
pivot_longer(
cols = c(
Rank_Prod,
Rank_ASV,
Rank_SSI,
Rank_SHAP_Stb,
Rank_SHAP_SSI,
Rank_SHAP_Eff
),
names_to = "Metodologia",
values_to = "Posicao"
) %>%
mutate(
Metodologia = factor(
Metodologia,
levels = c(
"Rank_Prod",
"Rank_ASV",
"Rank_SSI",
"Rank_SHAP_Stb",
"Rank_SHAP_SSI",
"Rank_SHAP_Eff"
),
labels = c(
"Grain Yield",
"ASV (Linear)",
"SSI (Linear)",
"SHAP Stability",
"SHAP SSI",
"SHAP Effect"
)
)
)
figure_5 <- ggplot(
dados_long,
aes(
x = Metodologia,
y = Posicao,
group = GEN,
color = GEN
)
) +
geom_line(
linewidth = 1,
alpha = 0.8
) +
geom_point(
size = 2,
shape = 21,
fill = "white",
stroke = 1.5
) +
geom_text(
data = subset(
dados_long,
Metodologia == "Grain Yield"
),
aes(
label = GEN
),
hjust = 2,
fontface = "bold",
size = 4,
family = "serif"
) +
geom_text(
data = subset(
dados_long,
Metodologia == "SHAP Effect"
),
aes(
label = GEN
),
hjust = -1,
fontface = "bold",
size = 4,
family = "serif"
) +
scale_color_manual(
values = as.vector(
pals::glasbey(9)
)
) +
scale_y_reverse(
breaks = 1:9
) +
coord_cartesian(
clip = "off"
) +
labs(
x = "Selection Framework",
y = "Genotype Rank (1 = Best)"
) +
theme_classic(
base_size = 13
) +
theme(
strip.background = element_blank(),
panel.background = element_rect(
color = "black",
fill = "white"
),
panel.grid = element_blank(),
legend.position = "none",
plot.margin = ggplot2::margin(
t = 2,
r = 18,
b = 2,
l = 18
),
axis.line.x = element_blank(),
axis.line.y = element_line(
color = "black"
),
axis.text.y = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 10,
angle = 0,
color = "black",
family = "serif"
),
axis.title.y = element_text(
size = 12,
color = "black",
family = "serif"
),
axis.title.x = element_text(
size = 10,
color = "black",
family = "serif"
),
axis.ticks = element_blank()
)
print(figure_5)

Spearman rank correlations are calculated among the six genotype-selection criteria. Positive correlations indicate that two criteria tend to assign similar positions to the genotypes, whereas negative correlations indicate opposing ranking patterns.
The comparison includes grain yield, AMMI stability, classical simultaneous selection, SHAP stability, SHAP-based simultaneous selection, and mean SHAP effect.
colunas_rank <- dados_resultado %>%
select(
Rank_Prod,
Rank_ASV,
Rank_SSI,
Rank_SHAP_Stb,
Rank_SHAP_SSI,
Rank_SHAP_Eff
) %>%
as.data.frame()
colnames(
colunas_rank
) <- c(
"Yield",
"ASV (Linear)",
"SSI (Linear)",
"SHAP Stability",
"SHAP SSI",
"SHAP Effect"
)
matriz_corr <- cor(
colunas_rank,
method = "spearman"
)
round(
matriz_corr,
2
)
Yield ASV (Linear) SSI (Linear) SHAP Stability SHAP SSI
Yield 1.00 0.02 0.70 -0.02 0.80
ASV (Linear) 0.02 1.00 0.68 0.45 0.15
SSI (Linear) 0.70 0.68 1.00 0.33 0.73
SHAP Stability -0.02 0.45 0.33 1.00 0.48
SHAP SSI 0.80 0.15 0.73 0.48 1.00
SHAP Effect 1.00 0.02 0.70 -0.02 0.80
SHAP Effect
Yield 1.00
ASV (Linear) 0.02
SSI (Linear) 0.70
SHAP Stability -0.02
SHAP SSI 0.80
SHAP Effect 1.00
The upper triangular correlation matrix represents the direction and magnitude of the Spearman associations. The numerical coefficients are displayed inside the corresponding cells.
figure_6 <- ggcorrplot::ggcorrplot(
matriz_corr,
method = "square",
lab = TRUE,
lab_size = 4,
show.diag = FALSE,
type = "upper",
legend.title = "Correlation",
colors = c(
"#DB241F",
"white",
"#4ADC36"
)
) +
labs(
x = "",
y = ""
) +
theme(
strip.background = element_rect(
color = "black",
fill = "white"
),
panel.background = element_rect(
color = "black",
fill = "white"
),
panel.grid = element_blank(),
legend.position = "right",
plot.margin = ggplot2::margin(
t = 0,
r = 0,
b = 0,
l = 0
),
legend.text = element_text(
size = 12,
family = "serif"
),
legend.title = element_text(
size = 14,
family = "serif",
vjust = 0.5
),
axis.line.x = element_blank(),
axis.line.y = element_line(
color = "black"
),
axis.text.y = element_text(
size = 12,
angle = 0,
color = "black",
family = "serif"
),
axis.text.x = element_text(
size = 12,
angle = 90,
hjust = 0.5,
vjust = 0.5,
color = "black",
family = "serif"
),
axis.title = element_blank(),
axis.ticks = element_blank(),
legend.key = element_blank(),
strip.text = element_text(
size = 14,
family = "serif",
color = "black"
)
)
print(figure_6)

sessionInfo()
R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26200)
Matrix products: default
LAPACK version 3.12.1
locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8 LC_CTYPE=Portuguese_Brazil.utf8
[3] LC_MONETARY=Portuguese_Brazil.utf8 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.utf8
time zone: America/Sao_Paulo
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggcorrplot_0.2.0 ggh4x_0.3.1 pals_1.10
[4] iBreakDown_2.1.2 DALEX_2.5.3 randomForest_4.7-1.2
[7] tidyr_1.3.2 dplyr_1.2.1 ggplot2_4.0.3
[10] workflowr_1.7.2
loaded via a namespace (and not attached):
[1] gtable_0.3.6 xfun_0.54 bslib_0.9.0 processx_3.8.6
[5] lattice_0.22-7 callr_3.7.6 vctrs_0.7.1 tools_4.5.1
[9] ps_1.9.1 generics_0.1.4 tibble_3.3.1 pkgconfig_2.0.3
[13] Matrix_1.7-4 RColorBrewer_1.1-3 S7_0.2.1 lifecycle_1.0.5
[17] compiler_4.5.1 farver_2.1.2 stringr_1.6.0 git2r_0.36.2
[21] mapproj_1.2.12 getPass_0.2-4 httpuv_1.6.16 htmltools_0.5.9
[25] maps_3.4.3 sass_0.4.10 yaml_2.3.12 later_1.4.4
[29] pillar_1.11.1 jquerylib_0.1.4 whisker_0.4.1 cachem_1.1.0
[33] nlme_3.1-168 tidyselect_1.2.1 digest_0.6.39 stringi_1.8.7
[37] reshape2_1.4.5 purrr_1.2.1 labeling_0.4.3 splines_4.5.1
[41] rprojroot_2.1.1 fastmap_1.2.0 grid_4.5.1 colorspace_2.1-2
[45] cli_3.6.5 magrittr_2.0.4 dichromat_2.0-0.1 utf8_1.2.6
[49] withr_3.0.2 scales_1.4.0 promises_1.5.0 rmarkdown_2.30
[53] httr_1.4.7 otel_0.2.0 evaluate_1.0.5 knitr_1.50
[57] mgcv_1.9-4 rlang_1.1.7 Rcpp_1.1.1 glue_1.8.0
[61] rstudioapi_0.17.1 jsonlite_2.0.0 R6_2.6.1 plyr_1.8.9
[65] fs_1.6.6
Department of Statistics - Federal University of Viçosa, Viçosa 36570-900, MG, Brazil; corresponding author, moysesnascim@ufv.br↩︎
Graduate Program in Plant Production - Federal University of Tocantins, Gurupi 77410-530, TO, Brazil; noe.eiterer@uft.edu.br↩︎
Department of Statistics - Federal University of Viçosa, Viçosa 36570-900, MG, Brazil; ana.campana@ufv.br↩︎
Department of Statistics - Federal University of Viçosa, Viçosa 36570-900, MG, Brazil; weverton.costa@ufv.br↩︎
Department of Statistics - Federal University of Viçosa, Viçosa 36570-900, MG, Brazil; wanessa.a.lima@ufv.br↩︎
Department of Agronomy - University of Florida, Gainesville, FL 32611, USA; jhernandezjarqui@ufl.edu↩︎