diff --git a/R/calculate_go_enrichment.R b/R/calculate_go_enrichment.R index febb25df..12dd462e 100644 --- a/R/calculate_go_enrichment.R +++ b/R/calculate_go_enrichment.R @@ -82,12 +82,12 @@ go_enrichment <- function(...) { #' determines if the enrichment analysis should be performed in order to check for both enrichemnt and #' deenrichemnt or only one of the two. This affects the statistics performed and therefore also the displayed #' plot. -#' @param replace_long_name a logical argument that specifies if GO term names above 50 characters should -#' be replaced by the GO ID instead for the plot. This ensures that the plotting area doesn't become +#' @param replace_long_name a logical argument that specifies if GO term names above 50 characters should +#' be replaced by the GO ID instead for the plot. This ensures that the plotting area doesn't become #' too small due to the long name. The default is `TRUE`. -#' @param label_move_frac a numeric argument between 0 and 1 that specifies which labels should be +#' @param label_move_frac a numeric argument between 0 and 1 that specifies which labels should be #' moved outside of the bar. The default is 0.2, which means that the labels of all bars that have a size -#' of 20% or less of the largest bar are moved to the right of the bar. This prevents labels from +#' of 20% or less of the largest bar are moved to the right of the bar. This prevents labels from #' overlapping with the bar boundaries. #' @param min_n_detected_proteins_in_process is a numeric argument that specifies the minimum number of #' detected proteins required for a GO term to be displayed in the plot. The default is 1, meaning @@ -364,7 +364,7 @@ if you used the right organism ID.", prefix = "\n", initial = "")) } } %>% tidyr::complete(.data$go_id, tidyr::nesting(!!rlang::ensym(is_significant), n_sig), fill = list(n_has_process = 0)) %>% - dplyr::ungroup() %>% + dplyr::ungroup() %>% tidyr::drop_na(.data$go_id) @@ -447,9 +447,9 @@ if you used the right organism ID.", prefix = "\n", initial = "")) filtered_result_table <- result_table %>% dplyr::ungroup() %>% dplyr::filter(.data$n_detected_proteins_in_process >= min_n_detected_proteins_in_process) - - if(replace_long_name){ - filtered_result_table <- filtered_result_table %>% + + if (replace_long_name) { + filtered_result_table <- filtered_result_table %>% mutate(term = ifelse(nchar(.data$term) > 50, .data$go_id, .data$term)) } @@ -468,10 +468,10 @@ if you used the right organism ID.", prefix = "\n", initial = "")) plot_input <- filtered_result_table %>% dplyr::ungroup() %>% dplyr::mutate(neg_log_sig = -log10(!!rlang::ensym(type))) %>% - dplyr::group_by({{ group }}) %>% - dplyr::mutate(n = 1:dplyr::n()) %>% + dplyr::group_by({{ group }}) %>% + dplyr::mutate(n = 1:dplyr::n()) %>% dplyr::filter(n <= top) - # dplyr::slice(1:top) + # dplyr::slice(1:top) } else { split_cutoff <- stringr::str_split(plot_cutoff, pattern = " ", simplify = TRUE) type <- split_cutoff[1] @@ -481,9 +481,9 @@ if you used the right organism ID.", prefix = "\n", initial = "")) dplyr::mutate(neg_log_sig = -log10(!!rlang::ensym(type))) %>% dplyr::filter(!!rlang::ensym(type) <= threshold) } - + # move label if bar is less than 20% (default) of largest bar - plot_input <- plot_input %>% + plot_input <- plot_input %>% mutate(hjust = ifelse((.data$neg_log_sig / max(.data$neg_log_sig)) < label_move_frac, -0.15, 1.05)) if (plot_style == "barplot") {