Add missing correlation plot layers

This commit is contained in:
2024-09-12 03:43:29 -04:00
parent f90cb25f91
commit 67f4a66b87

View File

@@ -401,7 +401,6 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
if (!is.null(config$coord_cartesian)) { if (!is.null(config$coord_cartesian)) {
plot <- plot + coord_cartesian(ylim = config$coord_cartesian) plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
} }
plot plot
}, },
@@ -424,13 +423,21 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
if (!is.null(config$suppressor_label)) { if (!is.null(config$suppressor_label)) {
plot <- plot + annotate("text", x = config$suppressor_label$x, y = config$suppressor_label$y, label = config$suppressor_label$label) plot <- plot + annotate("text", x = config$suppressor_label$x, y = config$suppressor_label$y, label = config$suppressor_label$label)
} }
plot plot
}, },
"correlation" = plot + geom_point(shape = config$shape %||% 3, color = "gray70") + "correlation" = {
plot <- plot + geom_point(shape = config$shape %||% 3, color = "gray70") +
geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope, color = "tomato3") + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope, color = "tomato3") +
annotate("text", x = 0, y = 0, label = config$correlation_text), annotate("text", x = config$annotate_position$x, y = config$annotate_position$y, label = config$correlation_text)
if (!is.null(config$rect)) {
plot <- plot + geom_rect(aes(xmin = config$rect$xmin,
xmax = config$rect$xmax, ymin = config$rect$ymin, ymax = config$rect$ymax),
color = "grey20", size = 0.25, alpha = 0.1, fill = NA, inherit.aes = FALSE)
}
plot
},
"box" = { "box" = {
plot <- plot + geom_boxplot() plot <- plot + geom_boxplot()
@@ -590,8 +597,7 @@ generate_rank_plot_configs <- function(df, rank_var, zscore_var, var, is_lm = FA
label = paste("Deletion Suppressors =", nrow(df[df[[zscore_var]] <= -sd_band, ])) label = paste("Deletion Suppressors =", nrow(df[df[[zscore_var]] <= -sd_band, ]))
), ),
shape = 3, shape = 3,
size = 0.1, size = 0.1
position = "jitter"
) )
} }
@@ -633,6 +639,8 @@ generate_correlation_plot_configs <- function(df, variables) {
correlation_text = paste("R-squared =", round(df[[lm_r_squared_col]][1], 2)), correlation_text = paste("R-squared =", round(df[[lm_r_squared_col]][1], 2)),
shape = 3, shape = 3,
geom_smooth = TRUE, geom_smooth = TRUE,
rect = list(xmin = -2, xmax = 2, ymin = -2, ymax = 2), # To add the geom_rect layer
annotate_position = list(x = 0, y = 0), # Position for the R-squared text
legend_position = "right" legend_position = "right"
) )
} }