---
title: PKPG03
subtitle: Box Plot of Pharmacokinetic Parameters by Visit -- Plasma
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
library(ggplot2)
library(nestcolor)
adpp <- random.cdisc.data::cadpp
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Plot of CMAX by Visit
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r plot1, test = list(plot_v1 = "plot")}
# filtered parameter
adpp <- adpp %>% filter(PARAMCD == "CMAX", PPSPEC == "Plasma")
use_title <- paste0("Boxplot of ", as.character(unique(adpp$PARAM)), " by Visit")
use_subtitle <- paste0(
"Analyte:\nPK Parameter: ",
as.character(unique(adpp$PARAM)),
" (",
as.character(unique(adpp$AVALU)),
")"
)
use_footnote <- "Program: \nOutput:"
plot <- ggplot(adpp, aes(x = AVISIT, y = AVAL, fill = ACTARM)) +
geom_boxplot(outlier.size = 2) +
stat_boxplot(geom = "errorbar") +
stat_summary(geom = "point", fun = "mean", col = "black", size = 5, shape = 8, position = position_dodge(0.75)) +
geom_text(
data = . %>% dplyr::group_by(AVISIT, ACTARM) %>% dplyr::filter(AVAL %in% boxplot.stats(AVAL)$out),
aes(x = AVISIT, y = AVAL, label = SUBJID, color = ACTARM),
size = 3, hjust = -0.2, position = position_dodge(0.75)
) +
labs(
title = use_title,
subtitle = use_subtitle,
caption = use_footnote,
x = "Visit",
y = paste0(as.character(unique(adpp$PARAM)), " (", as.character(unique(adpp$AVALU)), ")")
) +
theme(plot.caption = element_text(hjust = 0)) +
theme_nest()
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}