R: extend 1-year AUC plot script with additional comparisons (256_l, 120_l vs Delphi; 120 vs 120_l; 256 vs 256_l) and generic xy helper
This commit is contained in:
@@ -44,6 +44,24 @@ make_comparison_plot <- function(data, y_col, title_text, y_label) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Helper to compare any two AUC columns (x vs y)
|
||||||
|
make_xy_plot <- function(data, x_col, y_col, title_text, x_label, y_label) {
|
||||||
|
ggplot(data, aes(x = .data[[x_col]], y = .data[[y_col]])) +
|
||||||
|
geom_abline(slope = 1, intercept = 0, color = "black", linetype = "dashed", linewidth = 0.5) +
|
||||||
|
geom_vline(xintercept = 0.5, color = "gray50", linetype = "dashed", linewidth = 0.4) +
|
||||||
|
geom_hline(yintercept = 0.5, color = "gray50", linetype = "dashed", linewidth = 0.4) +
|
||||||
|
geom_point(aes(fill = Colour), shape = 21, color = "white", stroke = 0.65, size = 2.2, alpha = 0.95, show.legend = FALSE) +
|
||||||
|
scale_fill_identity() +
|
||||||
|
coord_cartesian(xlim = c(0.3, 1.05), ylim = c(0.3, 1.05)) +
|
||||||
|
coord_fixed(ratio = 1) +
|
||||||
|
labs(title = title_text, x = x_label, y = y_label) +
|
||||||
|
theme_minimal(base_size = 10) +
|
||||||
|
theme(
|
||||||
|
plot.title = element_text(hjust = 0.5),
|
||||||
|
panel.grid.minor = element_blank()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
# Plot: AUC_256 vs AUC_Delphi (1 year gap)
|
# Plot: AUC_256 vs AUC_Delphi (1 year gap)
|
||||||
if (!all(c("auc_delphi", "auc_256") %in% names(df))) {
|
if (!all(c("auc_delphi", "auc_256") %in% names(df))) {
|
||||||
stop("Input CSV must contain columns 'auc_delphi' and 'auc_256'.")
|
stop("Input CSV must contain columns 'auc_delphi' and 'auc_256'.")
|
||||||
@@ -74,3 +92,67 @@ if (!"auc_120" %in% names(df)) {
|
|||||||
ggsave(filename = out_120, plot = p120, width = 7, height = 4, dpi = 600, bg = "white")
|
ggsave(filename = out_120, plot = p120, width = 7, height = 4, dpi = 600, bg = "white")
|
||||||
cat(sprintf("Saved: %s\n", out_120))
|
cat(sprintf("Saved: %s\n", out_120))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Plot: AUC_256_L vs AUC_Delphi (1 year gap)
|
||||||
|
if (!"auc_256_l" %in% names(df)) {
|
||||||
|
warning("Column 'auc_256_l' not found in CSV; skipping AUC_256_L vs AUC_Delphi plot.")
|
||||||
|
} else {
|
||||||
|
p256l <- make_comparison_plot(
|
||||||
|
data = df,
|
||||||
|
y_col = "auc_256_l",
|
||||||
|
title_text = "AUC_256_L vs AUC_Delphi 1 year gap",
|
||||||
|
y_label = "AUC_256_L"
|
||||||
|
)
|
||||||
|
out_256l <- file.path(out_dir, "model_comparison_auc_256_l_vs_delphi_1year.png")
|
||||||
|
ggsave(filename = out_256l, plot = p256l, width = 7, height = 4, dpi = 600, bg = "white")
|
||||||
|
cat(sprintf("Saved: %s\n", out_256l))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Plot: AUC_120_L vs AUC_Delphi (1 year gap)
|
||||||
|
if (!"auc_120_l" %in% names(df)) {
|
||||||
|
warning("Column 'auc_120_l' not found in CSV; skipping AUC_120_L vs AUC_Delphi plot.")
|
||||||
|
} else {
|
||||||
|
p120l <- make_comparison_plot(
|
||||||
|
data = df,
|
||||||
|
y_col = "auc_120_l",
|
||||||
|
title_text = "AUC_120_L vs AUC_Delphi 1 year gap",
|
||||||
|
y_label = "AUC_120_L"
|
||||||
|
)
|
||||||
|
out_120l <- file.path(out_dir, "fig_auc_120_l_vs_delphi_1year.png")
|
||||||
|
ggsave(filename = out_120l, plot = p120l, width = 7, height = 4, dpi = 600, bg = "white")
|
||||||
|
cat(sprintf("Saved: %s\n", out_120l))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Plot: AUC_120 vs AUC_120_L (1 year gap)
|
||||||
|
if (!all(c("auc_120", "auc_120_l") %in% names(df))) {
|
||||||
|
warning("Columns 'auc_120' and/or 'auc_120_l' not found in CSV; skipping AUC_120 vs AUC_120_L plot.")
|
||||||
|
} else {
|
||||||
|
p120_vs_120l <- make_xy_plot(
|
||||||
|
data = df,
|
||||||
|
x_col = "auc_120",
|
||||||
|
y_col = "auc_120_l",
|
||||||
|
title_text = "AUC_120 vs AUC_120_L 1 year gap",
|
||||||
|
x_label = "AUC_120",
|
||||||
|
y_label = "AUC_120_L"
|
||||||
|
)
|
||||||
|
out_120_vs_120l <- file.path(out_dir, "model_comparison_auc_120_vs_120_l_1year.png")
|
||||||
|
ggsave(filename = out_120_vs_120l, plot = p120_vs_120l, width = 7, height = 4, dpi = 600, bg = "white")
|
||||||
|
cat(sprintf("Saved: %s\n", out_120_vs_120l))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Plot: AUC_256 vs AUC_256_L (1 year gap)
|
||||||
|
if (!all(c("auc_256", "auc_256_l") %in% names(df))) {
|
||||||
|
warning("Columns 'auc_256' and/or 'auc_256_l' not found in CSV; skipping AUC_256 vs AUC_256_L plot.")
|
||||||
|
} else {
|
||||||
|
p256_vs_256l <- make_xy_plot(
|
||||||
|
data = df,
|
||||||
|
x_col = "auc_256",
|
||||||
|
y_col = "auc_256_l",
|
||||||
|
title_text = "AUC_256 vs AUC_256_L 1 year gap",
|
||||||
|
x_label = "AUC_256",
|
||||||
|
y_label = "AUC_256_L"
|
||||||
|
)
|
||||||
|
out_256_vs_256l <- file.path(out_dir, "model_comparison_auc_256_vs_256_l_1year.png")
|
||||||
|
ggsave(filename = out_256_vs_256l, plot = p256_vs_256l, width = 7, height = 4, dpi = 600, bg = "white")
|
||||||
|
cat(sprintf("Saved: %s\n", out_256_vs_256l))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user