diff --git a/DESCRIPTION b/DESCRIPTION index 111e75b..3350737 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cqtkit Title: Comprehensive C-QT Analysis From Data to Deliverables -Version: 1.0.0 +Version: 1.0.1 Authors@R: c( person("Matt", "Smith", , "matthews@a2-ai.com", role = c("aut", "cre")), person("Devin", "Pastoor", , "devin@a2-ai.com", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index 40b4a94..6bc4af8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# cqtkit 1.0.1 + +### Fixed +* Exposed the intended optional `legend_location` argument in `gof_residuals_trt_boxplots()`. +* Updated `predict_with_observations_plot` to use `trt_col` to group data allowing for styling. +* Updated `predict_with_observations_plot` and `predict_with_quantiles_plot` to keep default black color +for prediction line when other colors supplied. +* Updated `eda_quantiles_plot` with `plot_observations` to add individual data points to plot. + # cqtkit 1.0.0 * Initial public release. diff --git a/R/compute.R b/R/compute.R index 6b30a7d..241fe1c 100644 --- a/R/compute.R +++ b/R/compute.R @@ -1512,11 +1512,21 @@ compute_contrast_observations <- function( if (is.null(control_predictors)) { # Simple case: no control group subtraction - observed_df <- tibble::tibble( - group = "Observations", - conc = data %>% dplyr::pull(!!conc), - dv = data %>% dplyr::pull(!!dv) - ) + if (rlang::quo_is_null(trt)) { + # No treatment column provided, use default grouping + observed_df <- tibble::tibble( + group = "Observations", + conc = data %>% dplyr::pull(!!conc), + dv = data %>% dplyr::pull(!!dv) + ) + } else { + # Use treatment column for grouping + observed_df <- tibble::tibble( + group = data %>% dplyr::pull(!!trt), + conc = data %>% dplyr::pull(!!conc), + dv = data %>% dplyr::pull(!!dv) + ) + } } else { # Control group subtraction case trt_str <- rlang::as_name(trt) @@ -1527,7 +1537,7 @@ compute_contrast_observations <- function( # Individual ID+time matching (crossover studies) treatment_df <- data %>% dplyr::filter(!!rlang::sym(trt_str) == !!treatment_value) %>% - dplyr::select(!!id, !!ntime, !!conc, treatment_dv = !!dv) + dplyr::select(!!id, !!ntime, !!conc, !!trt, treatment_dv = !!dv) control_df <- data %>% dplyr::filter(!!rlang::sym(trt_str) == !!control_value) %>% @@ -1540,7 +1550,7 @@ compute_contrast_observations <- function( ) %>% dplyr::mutate(dv = .data$treatment_dv - .data$control_dv) %>% dplyr::transmute( - group = "Observations", + group = !!trt, conc = !!conc, dv ) @@ -1564,7 +1574,7 @@ compute_contrast_observations <- function( dplyr::left_join(control_means, by = rlang::as_name(ntime)) %>% dplyr::mutate(dv = !!dv - .data$control_mean_dv) %>% dplyr::transmute( - group = "Observations", + group = !!trt, conc = !!conc, dv ) diff --git a/R/eda.R b/R/eda.R index cd8fe04..9924a02 100644 --- a/R/eda.R +++ b/R/eda.R @@ -283,6 +283,7 @@ eda_qtc_comparison_plot <- function( #' @param xdata_col An unquoted column name for x data #' @param ydata_col An unquoted column name for y data #' @param trt_col An unquoted column name for treatment column to stratify the data by +#' @param plot_observations A boolean to include the raw individual data points as background points, default FALSE #' @param conf_int Numeric confidence interval level (default: 0.9) #' @param error_bars A string for setting which errorbars are shown, CI, SE, SD #' @param style A named list of arguments passed to style_plot() @@ -312,6 +313,7 @@ eda_quantiles_plot <- function( xdata_col, ydata_col, trt_col = NULL, + plot_observations = FALSE, conf_int = 0.90, error_bars = "CI", style = list() @@ -347,8 +349,23 @@ eda_quantiles_plot <- function( group = .data$.trt_group, color = .data$.trt_group ) - ) + - ggplot2::geom_point( + ) + + if (plot_observations) { + p <- p + + ggplot2::geom_point( + data = data, + ggplot2::aes( + x = !!xdata, + y = !!ydata, + color = !!trt, + ), + alpha = 0.25 + ) + } + + p <- p + + ggplot2::geom_point( ggplot2::aes( shape = .data$.trt_group ) @@ -356,6 +373,8 @@ eda_quantiles_plot <- function( ggplot2::geom_smooth(method = "lm", formula = y ~ x, level = conf_int) + ggplot2::theme_bw() + + p <- add_error_bars_to_plot(obs, p, NULL, error_bars, conf_int) caption <- p$labels$caption diff --git a/R/gof.R b/R/gof.R index bdbea95..1b9432f 100644 --- a/R/gof.R +++ b/R/gof.R @@ -688,6 +688,7 @@ gof_residuals_time_boxplots <- function( #' @param ntime_col An unquoted column name for nominal time since dose #' @param trt_col An unquoted column name for treatment group" #' @param residual_references Numeric vector of reference residual lines to add, default -2 and 2 +#' @param legend_location String for legend position (top, bottom, left, right) #' @param style A named list of arguments passed to style_plot() #' #' @return a ggarrange plot @@ -715,12 +716,15 @@ gof_residuals_trt_boxplots <- function( ntime_col, trt_col = NULL, residual_references = c(-2, 2), + legend_location = c("top", "bottom", "left", "right", "none"), style = list() ) { checkmate::assertDataFrame(data) checkmate::assert(checkmate::check_class(fit, "lme")) checkmate::assert_numeric(residual_references, null.ok = TRUE) + legend_location <- match.arg(legend_location) + dv <- rlang::enquo(dv_col) conc <- rlang::enquo(conc_col) time <- rlang::enquo(ntime_col) @@ -772,10 +776,13 @@ gof_residuals_trt_boxplots <- function( trt_plot <- ggpubr::ggarrange( plotlist = trtg_plots, ncol = 1, - common.legend = TRUE + common.legend = TRUE, + legend = legend_location ) - if (!is.null(style$title)) + + if (!is.null(style$title)) { trt_plot <- ggpubr::annotate_figure(trt_plot, top = style$title) + } return(trt_plot) } diff --git a/R/predict.R b/R/predict.R index d6e26aa..f5527df 100644 --- a/R/predict.R +++ b/R/predict.R @@ -135,6 +135,8 @@ predict_with_observations_plot <- function( attr(p, "fill_colors") <- stats::setNames("grey", ci_label) # default open circle for line group attr(p, "secondary_shapes") <- stats::setNames(1, "Predictions") + # default black color for predictions line + attr(p, "prediction_colors") <- stats::setNames("black", "Predictions") # Add reference line(s) p <- add_horizontal_references(p, reference_threshold) @@ -378,6 +380,8 @@ predict_with_quantiles_plot <- function( # Add attributes for styling attr(p, "fill_colors") <- stats::setNames("grey", ci_label) attr(p, "secondary_shapes") <- stats::setNames(1, "Predictions") + # default black color for predictions line + attr(p, "prediction_colors") <- stats::setNames("black", "Predictions") p <- add_horizontal_references(p, reference_threshold) p <- p + ggplot2::theme_bw() + ggplot2::labs(caption = caption) diff --git a/R/style.R b/R/style.R index 44c84a1..758b3bc 100644 --- a/R/style.R +++ b/R/style.R @@ -385,7 +385,10 @@ style_plot <- function( p, aesthetic = "color", groups = color_groups, - default_map = attr(p, "reference_colors") %||% character(0), + default_map = c( + attr(p, "reference_colors") %||% character(0), + attr(p, "prediction_colors") %||% character(0) + ), user_values = colors, user_labels = labels, scale_fn = ggplot2::scale_color_manual diff --git a/man/eda_quantiles_plot.Rd b/man/eda_quantiles_plot.Rd index 43df65c..07572b6 100644 --- a/man/eda_quantiles_plot.Rd +++ b/man/eda_quantiles_plot.Rd @@ -9,6 +9,7 @@ eda_quantiles_plot( xdata_col, ydata_col, trt_col = NULL, + plot_observations = FALSE, conf_int = 0.9, error_bars = "CI", style = list() @@ -23,6 +24,8 @@ eda_quantiles_plot( \item{trt_col}{An unquoted column name for treatment column to stratify the data by} +\item{plot_observations}{A boolean to include the raw individual data points as background points, default FALSE} + \item{conf_int}{Numeric confidence interval level (default: 0.9)} \item{error_bars}{A string for setting which errorbars are shown, CI, SE, SD} diff --git a/man/gof_residuals_trt_boxplots.Rd b/man/gof_residuals_trt_boxplots.Rd index f6ef29f..0f4ce2f 100644 --- a/man/gof_residuals_trt_boxplots.Rd +++ b/man/gof_residuals_trt_boxplots.Rd @@ -12,6 +12,7 @@ gof_residuals_trt_boxplots( ntime_col, trt_col = NULL, residual_references = c(-2, 2), + legend_location = c("top", "bottom", "left", "right", "none"), style = list() ) } @@ -30,6 +31,8 @@ gof_residuals_trt_boxplots( \item{residual_references}{Numeric vector of reference residual lines to add, default -2 and 2} +\item{legend_location}{String for legend position (top, bottom, left, right)} + \item{style}{A named list of arguments passed to style_plot()} } \value{