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.

gg_pkc_lineplot(
  data,
  time_var,
  analyte_var,
  group,
  stat = c("mean", "median"),
  variability = c("sd", "se", "ci", "iqr", "none"),
  log_y = TRUE,
  lloq = NA_real_
)

Arguments

data

(data.frame)
The dataset containing PK data.

time_var

(tidy-select)
The time variable (x-axis).

analyte_var

(tidy-select)
The concentration/analyte variable (y-axis).

group

(tidy-select)
The grouping/treatment variable.

stat

(string)
Primary summary statistic: "mean" or "median". Default is "mean".

variability

(string)
Variability measure: "sd", "se", "ci", "iqr", or "none". Default is "sd".

log_y

(logical)
Whether to apply log10 scale to the y-axis. Default is TRUE.

lloq

(numeric or NULL)
Lower Limit of Quantification. Default is NA_real_.

Value

A ggplot object.

Examples

# 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"
  )