Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-24 fixing bug for volcano labels #25

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ 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 @@ -311,24 +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)) +
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))}
} +
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) {
Expand Down