Skip to content

Commit

Permalink
added arguments:
Browse files Browse the repository at this point in the history
prob_obs_byexptile, prob_obs_bydose_plac,
lineranges_doselabel,
proj_bydose

these enable various on off customization as per a recent client request
  • Loading branch information
certara-smouksassi committed Mar 26, 2024
1 parent b8b7b58 commit 98c0daf
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 21 deletions.
77 changes: 56 additions & 21 deletions R/gglogisticexpdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ plogis <- function(x) exp(x)/(1+exp(x))
#' @param dose_plac_value string identifying placebo in DOSE column
#' @param xlab text to be used as x axis label
#' @param ylab text to be used as y axis label
#' @param prob_obs_byexptile observed probability by exptile `TRUE`/`FALSE`
#' @param prob_text_size probability text size default to 5
#' @param prob_obs_bydose observed probability by dose `TRUE`/`FALSE`
#' @param prob_obs_bydose_plac observed probability by placebo dose `TRUE`/`FALSE`
#' @param N_text_size N responders/Ntotal by exposure bin text size default to 5
#' @param binlimits_text_size 5 binlimits text size
#' @param binlimits_ypos binlimits y position default to 0
Expand All @@ -50,6 +52,8 @@ plogis <- function(x) exp(x)/(1+exp(x))
#' @param dist_scale scaling parameter for ggridges default to 0.9
#' @param lineranges_ypos where to put the lineranges -1
#' @param lineranges_dodge lineranges vertical dodge value 1
#' @param lineranges_doselabel `TRUE`/`FALSE`
#' @param proj_bydose project the probabilities on logistic curve `TRUE`/`FALSE`
#' @param yproj project the probabilities on y axis `TRUE`/`FALSE`
#' @param yproj_xpos y projection x position 0
#' @param yproj_dodge y projection dodge value 0.2
Expand Down Expand Up @@ -215,8 +219,10 @@ gglogisticexpdist <- function(data = effICGI,
dose_plac_value = "Placebo",
xlab = "Exposure Values",
ylab ="Probability of Response",
prob_obs_byexptile = TRUE,
prob_text_size = 5,
prob_obs_bydose = TRUE,
prob_obs_bydose_plac = FALSE,
N_text_size = 5,
binlimits_text_size = 5,
binlimits_ypos = 0,
Expand All @@ -226,6 +232,8 @@ gglogisticexpdist <- function(data = effICGI,
dist_scale = 0.9,
lineranges_ypos = 0.2,
lineranges_dodge = 0.15,
lineranges_doselabel = FALSE,
proj_bydose = TRUE,
yproj = TRUE,
yproj_xpos = 0,
yproj_dodge = 0.2,
Expand Down Expand Up @@ -500,22 +508,27 @@ gglogisticexpdist <- function(data = effICGI,
stat="smooth",
method = "glm", method.args = list(family = "binomial"),
color="black", alpha = 0.5,
ggplot2::aes(linetype = "Logistic Fit 95% CI"))+
ggplot2::geom_line(data = predict_by_endpoint_expname_dose,
ggplot2::aes_string(y = "yhat", col = color_fill),
alpha = 0.4, linewidth = 2)+
ggplot2::geom_line(data = predict_by_endpoint_expname_dose2,
ggplot2::aes_string(y = "yhat", col = color_fill),
alpha = 0.4, linewidth = 2.5)+
ggplot2::geom_point(data = predict_by_endpoint_expname,
ggplot2::aes_string(x = "medexp", y = "ymid50", col = color_fill),
alpha = 0.4, size = 5)


ggplot2::aes(linetype = "Logistic Fit 95% CI"))

if(proj_bydose){
p1proj <- p1 +
ggplot2::geom_line(data = predict_by_endpoint_expname_dose,
ggplot2::aes_string(y = "yhat", col = color_fill),
alpha = 0.4, linewidth = 2)+
ggplot2::geom_line(data = predict_by_endpoint_expname_dose2,
ggplot2::aes_string(y = "yhat", col = color_fill),
alpha = 0.4, linewidth = 2.5)+
ggplot2::geom_point(data = predict_by_endpoint_expname,
ggplot2::aes_string(x = "medexp", y = "ymid50", col = color_fill),
alpha = 0.4, size = 5)
}
if(!proj_bydose){
p1proj <- p1
}

if(exposure_distribution=="lineranges") {
lineranges_ypos <- as.character(lineranges_ypos)
p1l <- p1 +
p1l <- p1proj +
ggplot2::geom_linerange(data = data.long.summaries.dose, linewidth = 2, alpha = 0.4,
ggplot2::aes_string(xmin = "quant_10", xmax = "quant_90",y = lineranges_ypos,
col = color_fill,
Expand All @@ -534,22 +547,38 @@ gglogisticexpdist <- function(data = effICGI,
group= paste0("interaction(",paste(as.character(c(DOSEinputvar,color_fill)) ,collapse=",",sep=""),")")
),
position = ggstance::position_dodgev(height = lineranges_dodge))

if(lineranges_doselabel){
p1lt <- p1l +
ggplot2::geom_text(data=data.long.summaries.dose, vjust = 1, size = 5, show.legend = FALSE,
ggplot2::aes_string(x="quant_90",y = lineranges_ypos,
label = "DOSE",
col = color_fill,
group= paste0("interaction(",paste(as.character(c(DOSEinputvar,color_fill)) ,collapse=",",sep=""),")")
),
position = ggstance::position_dodgev(height = lineranges_dodge))
}
if(!lineranges_doselabel){
p1lt <- p1l
}

}
if(exposure_distribution!="lineranges") {
p1l <- p1
p1lt <- p1proj
}

p2e <- p1l +
p2e <- p1lt +
ggplot2::geom_pointrange(data = data.long.summaries.exposure, size = 1,
ggplot2::aes(shape = "Observed probability by exposure split",
x = medexp, y = prob, ymin = prob+1.959*SE, ymax=prob-1.959*SE),
alpha = 0.5)
if(prob_obs_bydose){
data.long.summaries.dose.plot <- data.long.summaries.dose
if(!prob_obs_bydose_plac){
data.long.summaries.dose.plot[data.long.summaries.dose.plot[,color_fill]==dose_plac_value,"N"] <- NA
data.long.summaries.dose.plot[data.long.summaries.dose.plot[,color_fill]==dose_plac_value,"Ntot"] <- NA
data.long.summaries.dose.plot[data.long.summaries.dose.plot[,color_fill]==dose_plac_value,"prob"] <- NA

}
p2d <- p2e +
ggplot2::geom_pointrange(data = data.long.summaries.dose.plot, alpha = 0.5, size = 1,
ggplot2::aes(x = medexp, y = prob, col = !!sym(color_fill),
Expand All @@ -567,9 +596,15 @@ gglogisticexpdist <- function(data = effICGI,
if(!prob_obs_bydose){
p2d <- p2e
}
p2 <- p2d +
ggplot2::geom_text(data=data.long.summaries.exposure, vjust = 0, size = prob_text_size, show.legend = FALSE,
ggplot2::aes(x = medexp, y = prob, label = paste(100*round(prob,2),"%","\n",sep="")))+
if(prob_obs_byexptile) {
p2 <- p2d +
ggplot2::geom_text(data=data.long.summaries.exposure, vjust = 0, size = prob_text_size, show.legend = FALSE,
ggplot2::aes(x = medexp, y = prob, label = paste(100*round(prob,2),"%","\n",sep="")))
}
if(!prob_obs_byexptile) {
p2 <- p2d
}
p2t <- p2 +
ggplot2::geom_text(data = xintercepts, ggplot2::aes(label=round(intercept,1), x = intercept, y = binlimits_ypos) ,
vjust = 0, size = binlimits_text_size,color = binlimits_color)+
ggplot2::geom_text(data = data.long.summaries.exposure, y = Inf, vjust = 1, size = N_text_size,
Expand All @@ -578,7 +613,7 @@ gglogisticexpdist <- function(data = effICGI,
if(exposure_distribution=="distributions") {
data.long.ridges <- data.long
data.long.ridges[data.long.ridges[,DOSEinputvar]==dose_plac_value,"expvalue"] <- NA
p2d <- p2 +
p2d <- p2t +
ggridges::geom_density_ridges(data = data.long.ridges,
ggplot2::aes(x = expvalue, y = keynumeric,
group = interaction(!!sym(color_fill),!!sym(DOSEinputvar)),
Expand All @@ -593,7 +628,7 @@ gglogisticexpdist <- function(data = effICGI,
alpha = 0.5, show.legend = FALSE)
}
if(exposure_distribution!="distributions") {
p2d <- p2
p2d <- p2t
}

if(yproj) {
Expand Down
12 changes: 12 additions & 0 deletions man/gglogisticexpdist.Rd

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

0 comments on commit 98c0daf

Please sign in to comment.