Skip to content

Commit

Permalink
issue-24 bug fix for plot_volcano labels
Browse files Browse the repository at this point in the history
  • Loading branch information
delfarahalireza committed Mar 14, 2024
1 parent 6e59e5a commit 69d5e97
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ diffex_fdr <- function(term_data) {
#'
#' @export
plot_volcano <- function(
regression_significance,
max_p_trans = 10,
FDR_cutoff = 0.1,
feature_labels = NULL
) {
regression_significance,
max_p_trans = 10,
FDR_cutoff = 0.1,
feature_labels = NULL
) {

checkmate::assertDataFrame(regression_significance)
stopifnot("term" %in% colnames(regression_significance))
Expand All @@ -314,16 +314,20 @@ plot_volcano <- function(
regression_significance %>%
dplyr::filter(!is.na(p.value)) %>%
dplyr::mutate(
p.value.trans = trans_pvalues(p.value, max_p_trans = max_p_trans),
p.value.trans = trans_pvalues_temp(p.value, max_p_trans = max_p_trans),
is_discovery = qvalue < FDR_cutoff
) %>%
ggplot(aes_string(x = effect_var)) +
ggplot(aes_string(x = effect_var)) +
{if ("compoundName" %in% colnames(regression_significance)) {
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 {geom_point(aes(y = p.value.trans, color = is_discovery))}
} +
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))
}
} +
facet_wrap(~term, scales = "free_x") +
scale_x_continuous("Effect size") +
scale_y_continuous(expression(-log[10] ~ "pvalue")) +
Expand Down

0 comments on commit 69d5e97

Please sign in to comment.