Creates a standard Pharmacokinetic (PK) concentration-time profile plot.
This function wraps ggplot2 calls to consistently format PK profiles,
handling log transformations, various summary statistics, and variability measures.
(data.frame)
The dataset containing PK data.
(tidy-select)
The time variable (x-axis).
(tidy-select)
The concentration/analyte variable (y-axis).
(tidy-select)
The grouping/treatment variable.
(string)
Primary summary statistic: "mean" or "median". Default is "mean".
(string)
Variability measure: "sd", "se", "ci", "iqr", or "none". Default is "sd".
(numeric)
Confidence level for error bars when variability = "ci" (default: 0.95).
(logical)
Whether to apply log10 scale to the y-axis. Default is TRUE.
(numeric or NULL)
Lower Limit of Quantification. Default is NA_real_.
(numeric, function, or NULL)
Breaks for a numeric x-axis, passed to ggplot2::scale_x_continuous().
The default NULL puts a break on every observed timepoint, which is
readable over a short window but not over a long one. Supply a vector
(e.g. seq(0, 600, by = 100)) or a break function
(e.g. scales::breaks_pretty()) for wider time ranges. Ignored when
time_var is a factor.
(numeric)
Width of the horizontal caps on the variability error bars. Default is
0.45. Set to 0 for no caps. Ignored when variability = "none".
(numeric)
Horizontal separation between groups at each timepoint. Default is 0.2.
Increase if error bar caps are wider than the dodge width and overlap.
A ggplot object of class crane_gg_pkc with an "ARD"
attribute: a data.frame of summary statistics (N, the primary stat,
and variability-specific bound names: mean_plus_sd/mean_minus_sd for
"sd", mean_plus_se/mean_minus_se for "se", upper_ci/lower_ci
for "ci", q75/q25 for "iqr", no bounds for "none") grouped by
time_var and group. Retrieve with attr(p, "ARD").
annotate_pkc_df() for related functionalities.
# Prepare PK Data using the built-in Theoph dataset
df_pk <- Theoph
df_pk$Time_Nominal <- round(df_pk$Time)
# Filter to specific timepoints to keep the table clean
df_pk <- df_pk[df_pk$Time_Nominal %in% c(0, 2, 4, 8, 24), ]
# Create a mock treatment group based on Dose
df_pk$Dose_Group <- ifelse(df_pk$Dose > 4.5, "High Dose", "Low Dose")
# Linear Scale Example (Baseline 0 is included)
gg_pkc_lineplot(
data = df_pk,
time_var = Time_Nominal,
analyte_var = conc,
group = Dose_Group,
stat = "mean",
variability = "sd",
log_y = FALSE
)
# Log Scale Example (Filter out 0s first to avoid log(0) warnings)
df_pk |>
dplyr::filter(conc > 0) |>
gg_pkc_lineplot(
time_var = Time_Nominal,
analyte_var = conc,
group = Dose_Group,
stat = "mean",
variability = "se",
log_y = TRUE,
lloq = 2.0
)
# Title, subtitle, axes labels and legend position customization
gg_pkc_lineplot(
data = df_pk,
time_var = Time_Nominal,
analyte_var = conc,
group = Dose_Group,
stat = "mean",
variability = "sd",
log_y = FALSE
) +
ggplot2::labs(
x = "Nominal time (hr)",
y = "Concentration (ng/mL)",
title = "Title",
subtitle = "Subtitle"
) +
ggplot2::theme(
legend.position = "top"
)