R/bsfnPlot.R

#' Create concentration-time curve after single dose of busulfan
#'
#' \code{bsfnPlot} will create concentration-time curve after single dose of busulfan
#'
#' @param bsfnConcTimeData data frame of concentration-time dataset having column names Subject, Time, and Conc (case-sensitive)
#' @param log y axis log 
#' @return The concentration-time curve
#' @export
#' @examples 
#' bsfnPlot(bsfnConcTime(Weight = 20, Dose = 200, N = 20))
#' @import dplyr
#' @import ggplot2
#' @seealso \url{https://asancpt.github.io/bsfnsim}

bsfnPlot <- function(bsfnConcTimeData, log = FALSE){
  bsfnConcTime <- bsfnConcTimeData 
  p <- ggplot(bsfnConcTime, aes(x=Time, y=Conc)) + 
    xlab("Time (hour)") + ylab("Concentration (mg/L)") +
    scale_x_continuous(breaks = seq(from = 0, to = 24, by = 4)) +
    geom_line(aes(group = Subject, colour = Conc)) + 
    stat_summary(fun.y = "mean", colour = "#F0E442", size = 1, geom = "line") +
    geom_hline(yintercept = 80, colour="red") + 
    geom_hline(yintercept = 40, colour="blue") + 
    geom_hline(yintercept = 10, colour="green") + theme_linedraw()
  
  if (log == TRUE) p <- p + scale_y_log10() #limits = c(0.1, max(80, ggConc$Conc))))
  return(p)
}

#' Create concentration-time curve after multiple doses of busulfan
#'
#' \code{bsfnPlotMulti} will create concentration-time curve after multiple doses of busulfan
#'
#' @param bsfnConcTimeMultiData data frame of concentration-time dataset having column names Subject, Time, and Conc (case-sensitive)
#' @param log y axis log 
#' @return The concentration-time curve
#' @export
#' @examples 
#' bsfnPlotMulti(bsfnConcTimeMulti(Weight = 20, Dose = 200, N = 20, Tau = 8, Repeat = 4))
#' @import dplyr
#' @import ggplot2
#' @seealso \url{https://asancpt.github.io/bsfnsim}

bsfnPlotMulti <- function(bsfnConcTimeMultiData, log = FALSE){
  bsfnConcTimeMulti <- bsfnConcTimeMultiData
  p <- ggplot(bsfnConcTimeMulti, aes(x=Time, y=Conc)) + #, group=Subject, colour = Conc)) + #Subject)) +
    xlab("Time (hour)") + ylab("Concentration (mg/L)") +
    scale_x_continuous(breaks = seq(0, 96, 12)) +
    geom_line(aes(group = Subject, colour = Conc)) + 
    stat_summary(fun.y = "mean", colour = "#F0E442", size = 1, geom = "line") +
    geom_hline(yintercept = 80, colour="red") + 
    geom_hline(yintercept = 40, colour="blue") + 
    geom_hline(yintercept = 10, colour="green") + theme_linedraw()
  
  if (log == TRUE) p <- p + scale_y_log10() #limits = c(0.1, max(80, ggConc$Conc))))
  return(p)
}
asancpt/busulfansim documentation built on May 31, 2019, 8:40 a.m.