From c5ecf99940d1a87ab6fc0e6cd465af2ebbc2db87 Mon Sep 17 00:00:00 2001 From: "Vera N. Karlbauer" Date: Thu, 5 Jun 2025 15:35:12 +0200 Subject: [PATCH] Fix minor plot rendering issues --- .../10_correction_batch_effects_unfiltered.Rmd | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/10_correction_batch_effects_unfiltered.Rmd b/scripts/10_correction_batch_effects_unfiltered.Rmd index f59a991..e3eace1 100644 --- a/scripts/10_correction_batch_effects_unfiltered.Rmd +++ b/scripts/10_correction_batch_effects_unfiltered.Rmd @@ -87,7 +87,7 @@ if (correction_variable_1 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -95,6 +95,7 @@ if (correction_variable_1 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screeplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -231,7 +232,8 @@ if (correction_variable_1 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of first batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_1 != "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, correction of second batch effect and PCA, results='asis'} @@ -250,7 +252,7 @@ if (correction_variable_2 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -258,6 +260,7 @@ if (correction_variable_2 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screenplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -394,7 +397,8 @@ if (correction_variable_2 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of second batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_2 != "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, correction of third batch effect and PCA, results='asis'} @@ -413,7 +417,7 @@ if (correction_variable_3 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -421,6 +425,7 @@ if (correction_variable_3 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screeplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -557,7 +562,8 @@ if (correction_variable_3 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of third batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_3 != "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, conversion M to Beta and save, include=FALSE}