---
title: PKPG01
subtitle: Plot of Mean Cumulative Percentage (%) of Recovered Drug in Urine
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
library(ggplot2)
library(nestcolor)
set.seed(123)
# loading in the data
adpp <- random.cdisc.data::cadpp
# filtering the rows for specific data entries
adpp <- adpp %>%
filter(PARAMCD == "RCPCINT", AVISIT == "CYCLE 1 DAY 1", PPCAT == "Plasma Drug X")
# adding or modifying specific columns
adpp <- adpp %>%
mutate(ARM = as.factor(TRT01A)) %>%
mutate(PARAM1 = "Fe") %>% # re-format PK parameter name
mutate(Time = as.numeric(gsub("PT*|\\.|H$", "", PPENINT))) %>%
droplevels() %>%
df_explicit_na()
# in cases where the cohorts are numeric it is possible to rename them
levels(adpp$ARM) <- c(
"A: Drug X",
"C: Combination"
)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## Plot with Two Cohorts
::: {.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) Cummulative Percentage (%) of Recovered Drug in Urine \nby Analyte, Visit: PK Evaluable Patients" # nolint: line_length.
use_subtitle <- "Analyte: Plasma Drug X \nVisit: CYCLE 1 DAY 1 \nPK Parameter:"
use_footnote <- "Program: \nOutput:"
separation_between_barplots <- 1.5
result <- g_lineplot(
df = adpp,
variables = control_lineplot_vars(
x = "Time",
y = "AVAL",
group_var = "ARM",
paramcd = "PARAM1",
y_unit = "AVALU"
),
alt_counts_df = adpp,
y_lab = "Cummulative Percentage",
x_lab = "Time (hours)",
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(),
position = ggplot2::position_dodge(width = 2)
)
plot <- result + theme(plot.caption = element_text(hjust = 0)) +
scale_x_continuous(breaks = c(12, 24))
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Plot with Six Cohorts
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
In this case we need to process the data further by artificially adding more random rows. Of course this step is not necessary in the case that data already has more cohorts.
```{r plot2, test = list(plot_v2 = "plot")}
adpp_hck <- adpp %>%
mutate(AVAL + 1 * rnorm(nrow(adpp), mean = 1, sd = 1)) %>%
mutate(ARM = as.factor(sample(
c(
"D: Drug D",
"E: Drug E",
"F: Drug F",
"G: Drug G"
),
nrow(adpp),
replace = TRUE,
prob = c(0.4, 0.3, 0.2, 0.1)
)))
adpp <- bind_rows(adpp, adpp_hck)
use_title <- "Plot of Mean (+/- SD) Cummulative Percentage (%) of Recovered Drug in Urine \nby Analyte, Visit: PK Evaluable Patients" # nolint: line_length.
use_subtitle <- "Analyte: Plasma Drug X \nVisit: CYCLE 1 DAY 1 \nPK Parameter:"
use_footnote <- "Program: \nOutput:"
separation_between_barplots <- 1.5
result <- g_lineplot(
df = adpp,
variables = control_lineplot_vars(
x = "Time",
y = "AVAL",
group_var = "ARM",
paramcd = "PARAM1",
y_unit = "AVALU"
),
alt_counts_df = adpp,
y_lab = "Cummulative Percentage",
x_lab = "Time (hours)",
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(),
position = ggplot2::position_dodge(width = 2)
)
plot <- result + theme(plot.caption = element_text(hjust = 0)) +
scale_x_continuous(breaks = c(12, 24))
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 >}}