#' Visualize DDIWAS results. Last updated 2020-06-17.
#'
#' @param ddiwas_results A tibble
#' @param ddiwas_title A string
#' @param groups_vector A list
#' @param colors_vector A list
#' @param min.or A numeric
#' @param max.or A numeric
#' @param num_tests A numeric
#' @param max.pval A numeric
#' @param yaxis_type A string
#' @return A highcharter plot \code{hc}
#' @export
visualize_ddiwas_alt <- function(ddiwas_results, ddiwas_title, groups_vector, colors_vector, min.or = 0.2, max.or = 10, num_tests, max.pval = 30, yaxis_type = "linear") {
library(tidyverse)
library(EmpiricalCalibration)
library(highcharter)
PATH <- "../data/"
# for high chart legend
x <- c("Drug:", "RxCUI ingredient:",
"OR:", "se:", "pvalue:",
"drugbank_description:",
"nA:", "nB:","nC:","nD")
y <- sprintf("{point.%s}", c("rxcui_ingr_name", "rxcui_ingr",
"or", "se","pval",
"drugbank_description",
"nA","nB","nC","nD"))
tltip <- tooltip_table(x, y)
# color variables for vertical line
color.black <- "#000000"
# vertical line at OR = 1
plotLine <- list(label = list(), color = color.black, width = 2, value = 1)
# horizontal lines at p=0.05 and bonferroni-corrected p-value
pvalue_horizontal_line <- list(label = list(),
width = 2,
value = -log10(0.05),
color = 'blue')
bonferroni_horizontal_line <- list(label = list(),
width = 2,
value = -log10(0.05/num_tests),
color = 'red')
# Create chart variable and define axis parameters
hc <- highchart() %>%
hc_title(text = ddiwas_title) %>%
hc_xAxis(title=list(text="Odds Ratio"),
type = 'logarithmic',
min=min.or,
max=max.or,
plotLines = list(plotLine)) %>%
hc_yAxis(title = list(text="-log10(pvalue)"),
type = yaxis_type,
max=max.pval,
plotLines = list(pvalue_horizontal_line, bonferroni_horizontal_line))
# Plot drugs
num_vector <- seq(1, length(groups_vector), by = 1)
for (i in num_vector){
dfgroup<-filter(ddiwas_results, group == groups_vector[i])
hc <- hc %>%
hc_add_series(
name=groups_vector[i],
dfgroup, type = "scatter",
hcaes(x = or, y= -log10(pval),value = rxcui_ingr_name),
marker = list(
fillColor = colors_vector[[i]][1],
lineColor = colors_vector[[i]][2],
lineWidth = 0.5)
)
}
hc <- hc %>% hc_tooltip(useHTML = TRUE, pointFormat = tltip)
return(hc)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.