---
title: PKCG03
subtitle: Plot of Mean PK Concentration Over Time by Cohort
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
library(ggplot2)
library(nestcolor)
adsl_f <- random.cdisc.data::cadsl %>%
filter(SAFFL == "Y" & ARM != "B: Placebo") %>%
df_explicit_na()
adpc <- random.cdisc.data::cadpc %>%
mutate(Patient_ID = sub(".*id-", "", USUBJID)) %>%
filter(PARAM == "Plasma Drug X") %>%
droplevels() %>%
df_explicit_na()
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## Plot in Linear Scale
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r plot1, test = list(plot_v1 = "plot")}
use_title <- "Plot of Mean (+/- SD) Plasma Concentrations Over Time by Treatment, \nPK Evaluable Patients"
use_subtitle <- "Analyte:"
use_footnote <- "Program: \nOutput:"
result <- g_lineplot(
df = adpc,
variables = control_lineplot_vars(
x = "NFRLT",
y = "AVAL",
group_var = "ARM",
paramcd = "PARAM",
y_unit = "AVALU",
subject_var = "USUBJID"
),
alt_counts_df = adsl_f,
y_lab = "Concentration",
y_lab_add_paramcd = FALSE,
y_lab_add_unit = TRUE,
interval = "mean_sdi",
whiskers = c("mean_sdi_lwr", "mean_sdi_upr"),
title = use_title,
subtitle = use_subtitle,
caption = use_footnote,
ggtheme = theme_nest()
)
plot <- result + theme(plot.caption = element_text(hjust = 0))
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Plot in Log Scale
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r plot2, warning = FALSE, test = list(plot_v2 = "plot")}
use_title <- "Plot of Mean (+/- SD) Log-Scale Plasma Concentrations Over Time by Treatment, \nPK Evaluable Patients"
use_subtitle <- "Analyte:"
use_footnote <- "Program: \nOutput:"
adpc <- adpc %>%
mutate(avalog = ifelse(AVAL != 0, AVAL, 0.001))
result <- g_lineplot(
df = adpc,
variables = control_lineplot_vars(
x = "NFRLT",
y = "avalog",
group_var = "ARM",
paramcd = "PARAM",
y_unit = "AVALU",
subject_var = "USUBJID"
),
alt_counts_df = adsl_f,
y_lab = "Concentration",
y_lab_add_paramcd = FALSE,
y_lab_add_unit = TRUE,
interval = "mean_sdi",
whiskers = c("mean_sdi_lwr", "mean_sdi_upr"),
title = use_title,
subtitle = use_subtitle,
caption = use_footnote,
ggtheme = theme_nest()
)
plot <- result + theme(plot.caption = element_text(hjust = 0)) +
ggplot2::scale_y_log10(breaks = c(0.001, 0.01, 0.1, 1, 10), labels = c(0.001, 0.01, 0.1, 1, 10))
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}