Skip to content

Commit 4c69cba

Browse files
committed
fixed square for Z > 20 in DIMS/export/generate_violin_plots_functions.R
1 parent dcdd971 commit 4c69cba

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

DIMS/export/generate_violin_plots_functions.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,20 @@ create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_meta
665665
for (metab_class in names(metab_perpage)) {
666666
# extract list of metabolites to plot on a page
667667
metab_zscores_df <- metab_perpage[[metab_class]]
668-
# extract original data for patient of interest (pt_name) before cut-offs
669-
patient_zscore_df <- metab_zscores_df %>% filter(Sample == patient_id)
670-
671-
# Remove patient column and change Z-score. If under -5 to -5 and if above 20 to 20.
668+
# copy Z-scores to Z_score_original for displaying values
669+
metab_zscores_df$Z_score_original <- metab_zscores_df$Z_score
670+
# Cap Z-scores under -5 to -5 and above 20 to 20
672671
metab_zscores_df <- metab_zscores_df %>%
673-
filter(Sample != patient_id) %>%
674672
mutate(Z_score = pmin(pmax(Z_score, -5), 20))
675673

674+
# extract original data for patient of interest (pt_name)
675+
patient_zscore_df <- metab_zscores_df %>%
676+
filter(Sample == patient_id)
677+
678+
# Remove patient of interest and retain only other patient data
679+
metab_zscores_df <- metab_zscores_df %>%
680+
filter(Sample != patient_id)
681+
676682
# subtitle per page
677683
sub_perpage <- gsub("_", " ", metab_class)
678684
# for IEM plots, put subtitle on two lines
@@ -733,7 +739,7 @@ create_violin_plot <- function(metab_zscores_df, patient_zscore_df, sub_perpage,
733739
# Add the Z-score at the right side of the plot
734740
geom_text(
735741
data = patient_zscore_df,
736-
aes(16, label = paste0("Z=", round(Z_score, 2))),
742+
aes(16, label = paste0("Z=", round(Z_score_original, 2))),
737743
hjust = "left", vjust = +0.2, size = 3, na.rm = TRUE
738744
) +
739745
# Set colour for the Z-score of the selected patient

0 commit comments

Comments
 (0)