Skip to content

Commit

Permalink
grey unsignificant on the plot #106
Browse files Browse the repository at this point in the history
  • Loading branch information
werpuc committed May 31, 2022
1 parent f4b366e commit 18c1d45
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
47 changes: 38 additions & 9 deletions R/plot_volcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' should be the same as used in \code{\link{create_volcano_dataset}} function.
#' @param color_times logical, indicating if different time points on the plot
#' are distinguishable by color.
#' @param show_insignificant_grey ...
#' @param hide_insignificant ...
#' @param relative ...
#' @param theoretical ...
#'
Expand Down Expand Up @@ -44,7 +46,11 @@
#' dat <- read_hdx(system.file(package = "HaDeX", "HaDeX/data/KD_180110_CD160_HVEM.csv"))
#' p_dat <- create_p_diff_uptake_dataset(dat)
#' plot_volcano(p_dat, show_confidence_limits = T)
#'
#'
#' plot_volcano(p_dat, show_confidence_limits = T, show_insignificant_grey = T)
#' plot_volcano(p_dat, show_confidence_limits = T, hide_insignificant = T)
#' plot_volcano(p_dat, show_confidence_limits = T, hide_insignificant = T, show_insignificant_grey = T)
#'
#' @export plot_volcano

plot_volcano <- function(p_dat,
Expand All @@ -54,9 +60,17 @@ plot_volcano <- function(p_dat,
show_confidence_limits = FALSE,
confidence_level = 0.98,
color_times = TRUE,
show_insignificant_grey = FALSE,
hide_insignificant = FALSE,
fractional = F,
theoretical = F) {

if(hide_insignificant & show_insignificant_grey){

message("Chosen parameters are in conflict. The unsignifiant values are in grey.")
hide_insignificant <- F

}

if (fractional){

Expand Down Expand Up @@ -102,12 +116,25 @@ plot_volcano <- function(p_dat,
P_value = p_dat[["P_value"]],
log_p_value = p_dat[["log_p_value"]])

y_threshold <- -log(1 - confidence_level)

t_value <- qt(c((1 - confidence_level)/2, 1-(1 - confidence_level)/2), df = 2)[2]
x_threshold <- t_value * mean(plot_dat[["err_value"]], na.rm = TRUE)/sqrt(length(plot_dat))

plot_dat <- plot_dat %>%
mutate(valid = abs(value) > x_threshold & log_p_value > y_threshold)

if(hide_insignificant) {

plot_dat <- filter(plot_dat, valid)

}

if (color_times){
if(color_times){

volcano_plot <- ggplot(plot_dat, aes(x = value, y = log_p_value)) +
geom_errorbar(aes(xmin = value - err_value, xmax = value + err_value), color = "grey77") +
geom_point(aes(color = as.factor(Exposure))) +
geom_errorbar(aes(xmin = value - err_value, xmax = value + err_value), alpha = 0.2) +
labs(title = paste0("Volcano Plot ", state_1, " " , state_2),
x = x_label,
y = "-log(P value)") +
Expand All @@ -117,7 +144,7 @@ plot_volcano <- function(p_dat,

volcano_plot <- ggplot(plot_dat, aes(x = value, y = log_p_value)) +
geom_point() +
geom_errorbar(aes(xmin = value - err_value, xmax = value + err_value), alpha = 0.2) +
geom_errorbar(aes(xmin = value - err_value, xmax = value + err_value), color = "grey77") +
labs(title = paste0("Volcano Plot ", state_1, " " , state_2),
x = x_label,
y = "-log(P value)")
Expand All @@ -135,11 +162,6 @@ plot_volcano <- function(p_dat,

if(show_confidence_limits){

y_threshold <- -log(1 - confidence_level)

t_value <- qt(c((1 - confidence_level)/2, 1-(1 - confidence_level)/2), df = 2)[2]
x_threshold <- t_value * mean(plot_dat[["err_value"]], na.rm = TRUE)/sqrt(length(plot_dat))

volcano_plot <- volcano_plot +
geom_segment(aes(x = -x_threshold, xend = -x_threshold, y = y_threshold, yend = Inf), linetype = "dashed", color = "red") +
geom_segment(aes(x = x_threshold, xend = x_threshold, y = y_threshold, yend = Inf), linetype = "dashed", color = "red") +
Expand All @@ -148,6 +170,13 @@ plot_volcano <- function(p_dat,

}

if(show_insignificant_grey){

volcano_plot <- volcano_plot +
geom_point(data = subset(plot_dat, !valid), aes(x = value, y = log_p_value), color = "grey77")

}

return(HaDeXify(volcano_plot))

}
8 changes: 2 additions & 6 deletions inst/HaDeX/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,15 @@ server <- function(input, output, session) {

observe({

if(has_modifications()){
hide("chosen_control")
}
if(has_modifications()){ hide("chosen_control") }

})

##

observe({

if(!has_modifications()){
show("chosen_control")
}
if(!has_modifications()){ show("chosen_control") }

})

Expand Down
4 changes: 4 additions & 0 deletions inst/HaDeX/server/tab_volcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,14 @@ alpha_interval <- reactive({

volcano_plot_out <- reactive({

# browser()

plot_volcano(volcano_data(),
state_1 = input[["vol_state_1"]],
state_2 = input[["vol_state_2"]],
color_times = input[["vol_color_times"]],
show_insignificant_grey = input[["vol_show_insignificant_grey"]],
hide_insignificant = input[["vol_hide_insignificant"]],
fractional = input[["vol_fractional"]],
theoretical = FALSE) + ## hard coded, no theoretical
# ## statistics
Expand Down
26 changes: 22 additions & 4 deletions inst/HaDeX/ui/ui_tab_volcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,32 @@ volcano_test <- function() HaDeX_plotSettingsSection(

title = "Test",

fluidPage(
fluidRow(
column(
width = 6,
checkboxInput_h(inputId = "vol_hide_insignificant",
label = "Hide insignificant values?",
value = F),
checkboxInput_h(inputId = "vol_show_insignificant_grey",
label = "Show insignificant values in grey?",
value = F)

),
column(
width = 6,
selectInput_h(inputId = "vol_p_adjustment_method",
label = "Choose method of adjustment:",
choices = c("none", "BH", "bonferroni"),
selected = "none")
)
)
)
# selectInput_h(inputId = "vol_test_type",
# label = "Select test type:",
# choices = c("Houde test for selected time points" = 1, "Houde test all time points" = 2), #, "semi-parametric test" = 3),
# selected = 1),
selectInput_h(inputId = "vol_p_adjustment_method",
label = "Choose method of adjustment:",
choices = c("none", "BH", "bonferroni"),
selected = "none")

)


Expand Down
10 changes: 10 additions & 0 deletions man/plot_volcano.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18c1d45

Please sign in to comment.