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".
(logical)
Whether to apply log10 scale to the y-axis. Default is TRUE.
(numeric or NULL)
Lower Limit of Quantification. Default is NA_real_.
A ggplot object.
# 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"
)