diff --git a/R/differential_expression.R b/R/differential_expression.R index f229b7e..7db0ceb 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -295,8 +295,7 @@ plot_volcano <- function( regression_significance, max_p_trans = 10, FDR_cutoff = 0.1, - feature_labels = NULL -) { + feature_labels = NULL) { checkmate::assertDataFrame(regression_significance) stopifnot("term" %in% colnames(regression_significance)) @@ -311,28 +310,30 @@ plot_volcano <- function( stop("volcano plot cannot be generated due to unknown test") } - regression_significance %>% - dplyr::filter(!is.na(p.value)) %>% - dplyr::mutate( - p.value.trans = trans_pvalues(p.value, max_p_trans = max_p_trans), - is_discovery = qvalue < FDR_cutoff - ) %>% - ggplot(aes_string(x = effect_var)) + - {if ("compoundName" %in% colnames(regression_significance)) { - geom_point(aes(y = p.value.trans, color = is_discovery, name = compoundName)) - } else { - geom_point(aes(y = p.value.trans, color = is_discovery)) - } - } + - {if ("compoundName" %in% colnames(regression_significance)) { - geom_text(aes(label = ifelse(compoundName %in% feature_labels, compoundName, ""), y = p.value.trans, vjust = -0.75)) - } - } + + grob <- ggplot( + regression_significance %>% + dplyr::filter(!is.na(p.value)) %>% + dplyr::mutate( + p.value.trans = trans_pvalues(p.value, max_p_trans = max_p_trans), + is_discovery = qvalue < FDR_cutoff + ), + aes_string(x = effect_var) + ) + facet_wrap(~term, scales = "free_x") + scale_x_continuous("Effect size") + scale_y_continuous(expression(-log[10] ~ "pvalue")) + scale_color_manual(values = c("FALSE" = "gray50", "TRUE" = "RED")) + theme_bw() + + if ("compoundName" %in% colnames(regression_significance)) { + grob <- grob + + geom_point(aes(y = p.value.trans, color = is_discovery, name = compoundName)) + + geom_text(aes(label = ifelse(compoundName %in% feature_labels, compoundName, ""), y = p.value.trans, vjust = -0.75)) + } else { + grob <- grob + + geom_point(aes(y = p.value.trans, color = is_discovery)) + } + return(grob) } trans_pvalues <- function(p, max_p_trans = 10) {