Skip to content

Commit

Permalink
controling where to put bin limits via binlimits_ypos and binlimits_c…
Browse files Browse the repository at this point in the history
…olor

add linerange to  logistic ,
docs
  • Loading branch information
certara-smouksassi committed Jan 5, 2024
1 parent 1c72272 commit 4fb5227
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 590 deletions.
14 changes: 8 additions & 6 deletions R/ggcontinuousexpdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ plogis <- function(x) exp(x)/(1+exp(x))
#' labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg"))
#'effICGI$STUDY <- factor(effICGI$STUDY)
#'effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI7,BRLS)
#' a <- ggcontinuousexpdist(data = effICGI |> filter(Endpoint =="ICGI7"), # long format filter to Endpoint of choice
#' a <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI7"),
#' response = "response",
#' endpoint = "Endpoint",
#' exposure_metrics = c("AUC"),
Expand All @@ -75,7 +75,7 @@ plogis <- function(x) exp(x)/(1+exp(x))
#' yproj_dodge = 20 ,
#' exposure_distribution ="distributions")
#'
#' b <- ggcontinuousexpdist(data = effICGI |> filter(Endpoint =="BRLS"), # long format filter to Endpoint of choice
#' b <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="BRLS"),
#' response = "response",
#' endpoint = "Endpoint",
#' exposure_metrics = c("AUC"),
Expand Down Expand Up @@ -109,6 +109,8 @@ ggcontinuousexpdist <- function(data = effICGI,
mean_obs_bydose = TRUE,
N_text_size = 5,
binlimits_text_size = 5,
binlimits_ypos = -Inf,
binlimits_color= "gray70",
dist_position_scaler = 0.2,
dist_offset = 0,
lineranges_ypos = -1,
Expand Down Expand Up @@ -374,7 +376,7 @@ ggcontinuousexpdist <- function(data = effICGI,
ymin = mean+1.959*SE,
ymax=mean-1.959*SE),
alpha = 0.5)
if(prob_obs_bydose){
if(mean_obs_bydose){
data.long.summaries.dose.plot <- data.long.summaries.dose
data.long.summaries.dose.plot[data.long.summaries.dose.plot[,DOSEinputvar]==dose_plac_value,"Ntot"] <- NA
data.long.summaries.dose.plot[data.long.summaries.dose.plot[,DOSEinputvar]==dose_plac_value,"mean"] <- NA
Expand All @@ -393,14 +395,14 @@ ggcontinuousexpdist <- function(data = effICGI,
))

}
if(!prob_obs_bydose){
if(!mean_obs_bydose){
p2d <- p2e
}
p2 <- p2d +
ggplot2::geom_text(data=data.long.summaries.exposure, vjust = 0, size = mean_text_size, show.legend = FALSE,
ggplot2::aes(x = medexp, y = mean, label = paste(round(mean,2),"\n",sep="")))+
ggplot2::geom_text(data = xintercepts, ggplot2::aes(label=round(intercept,1), x = intercept, y = -Inf) ,
vjust = 0, size = binlimits_text_size,color = "gray70")+
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,
ggplot2::aes(x = as.double(as.character(medexp)), label=paste(Ntot,sep="")))

Expand Down
22 changes: 14 additions & 8 deletions R/gglogisticexpdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ plogis <- function(x) exp(x)/(1+exp(x))
#' @param xlab text to be used as x axis label
#' @param ylab text to be used as y axis label
#' @param prob_text_size probability text size default to 5
#' @param prob_obs_bydose TRUE/FALSE
#' @param prob_obs_bydose observed probability by 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
#' @param binlimits_color binlimits text color default to "gray70"
#' @param dist_position_scaler space occupied by the distribution default to 0.2
#' @param dist_offset offset where the distribution position starts 0
#' @param lineranges_ypos where to put the lineranges 0.2
#' @param lineranges_ypos where to put the lineranges -1
#' @param lineranges_dodge lineranges vertical dodge value 1
#' @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 @@ -184,9 +187,12 @@ gglogisticexpdist <- function(data = effICGI,
prob_obs_bydose = TRUE,
N_text_size = 5,
binlimits_text_size = 5,
binlimits_ypos = 0,
binlimits_color= "gray70",
dist_position_scaler = 0.2,
dist_offset = 0,
lineranges_ypos = 0.2,
lineranges_dodge = 0.15,
yproj = TRUE,
yproj_xpos = 0,
yproj_dodge = 0.2,
Expand Down Expand Up @@ -427,11 +433,11 @@ gglogisticexpdist <- function(data = effICGI,
ggplot2::geom_linerange(data = data.long.summaries.dose, size = 2, alpha = 0.4,
ggplot2::aes_string(xmin = "quant_10", xmax = "quant_90",y = lineranges_ypos,
col = DOSEinputvar, group = DOSEinputvar),
position = ggstance::position_dodgev(height = 0.15),inherit.aes = FALSE)+
position = ggstance::position_dodgev(height = lineranges_dodge),inherit.aes = FALSE)+
ggplot2::geom_linerange(data = data.long.summaries.dose, size = 2.5, alpha = 0.4,
ggplot2::aes_string(xmin = "quant_25", xmax= "quant_75", y = lineranges_ypos,
col = DOSEinputvar, group = DOSEinputvar),
position = ggstance::position_dodgev(height = 0.15), inherit.aes = FALSE)+
position = ggstance::position_dodgev(height = lineranges_dodge), inherit.aes = FALSE)+
ggplot2::geom_point(data=data.long.summaries.dose, size = 5, alpha = 0.2,
ggplot2::aes_string(x="medexp",y = lineranges_ypos,
col = DOSEinputvar),
Expand Down Expand Up @@ -472,9 +478,9 @@ gglogisticexpdist <- function(data = effICGI,
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="")))+
ggplot2::geom_text(data = xintercepts, ggplot2::aes(label=round(intercept,1), x = intercept, y = 0) ,
vjust = 1, size = binlimits_text_size,color = "gray70")+
ggplot2::geom_text(data = data.long.summaries.exposure, y = 0, vjust = 0, size = N_text_size,
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,
ggplot2::aes(x = as.double(as.character(medexp)), label=paste(N,"/",Ntot,sep="")))

if(exposure_distribution=="distributions") {
Expand All @@ -486,7 +492,7 @@ gglogisticexpdist <- function(data = effICGI,
group = !!rlang::sym(DOSEinputvar),
col = !!rlang::sym(DOSEinputvar),
height = ggplot2::after_stat(ndensity)),
rel_min_height = 0.05,alpha = 0.1, scale = 0.9,
rel_min_height = 0.05, alpha = 0.1, scale = 0.9,
quantile_lines = TRUE, quantiles = c(0.1,0.25, 0.5, 0.75,0.9))+
ggplot2::geom_label(data = percentineachbreakcategory,
ggplot2::aes(color = !!rlang::sym(DOSEinputvar), y = keynumeric, x= xmed, label = round(100*percentage,0) ),
Expand Down
Loading

0 comments on commit 4fb5227

Please sign in to comment.