TLG Catalog - Stable
  • Stable
    • Dev
  1. Graphs
  2. Other
  3. BRG01
  • Introduction

  • Tables
    • ADA
      • ADAT01
      • ADAT02
      • ADAT03
      • ADAT04A
      • ADAT04B
    • Adverse Events
      • AET01
      • AET01_AESI
      • AET02
      • AET02_SMQ
      • AET03
      • AET04
      • AET04_PI
      • AET05
      • AET05_ALL
      • AET06
      • AET06_SMQ
      • AET07
      • AET09
      • AET09_SMQ
      • AET10
    • Concomitant Medications
      • CMT01
      • CMT01A
      • CMT01B
      • CMT02_PT
    • Deaths
      • DTHT01
    • Demography
      • DMT01
    • Disclosures
      • DISCLOSUREST01
      • EUDRAT01
      • EUDRAT02
    • Disposition
      • DST01
      • PDT01
      • PDT02
    • ECG
      • EGT01
      • EGT02
      • EGT03
      • EGT04
      • EGT05_QTCAT
    • Efficacy
      • AOVT01
      • AOVT02
      • AOVT03
      • CFBT01
      • CMHT01
      • COXT01
      • COXT02
      • DORT01
      • LGRT02
      • MMRMT01
      • ONCT05
      • RATET01
      • RBMIT01
      • RSPT01
      • TTET01
    • Exposure
      • EXT01
    • Lab Results
      • LBT01
      • LBT02
      • LBT03
      • LBT04
      • LBT05
      • LBT06
      • LBT07
      • LBT08
      • LBT09
      • LBT10
      • LBT10_BL
      • LBT11
      • LBT11_BL
      • LBT12
      • LBT12_BL
      • LBT13
      • LBT14
      • LBT15
    • Medical History
      • MHT01
    • Pharmacokinetic
      • PKCT01
      • PKPT02
      • PKPT03
      • PKPT04
      • PKPT05
      • PKPT06
      • PKPT07
      • PKPT08
      • PKPT11
    • Risk Management Plan
      • RMPT01
      • RMPT03
      • RMPT04
      • RMPT05
      • RMPT06
    • Safety
      • ENTXX
    • Vital Signs
      • VST01
      • VST02
  • Listings
    • ADA
      • ADAL02
    • Adverse Events
      • AEL01
      • AEL01_NOLLT
      • AEL02
      • AEL02_ED
      • AEL03
      • AEL04
    • Concomitant Medications
      • CML01
      • CML02A_GL
      • CML02B_GL
    • Development Safety Update Report
      • DSUR4
    • Disposition
      • DSL01
      • DSL02
    • ECG
      • EGL01
    • Efficacy
      • ONCL01
    • Exposure
      • EXL01
    • Lab Results
      • LBL01
      • LBL01_RLS
      • LBL02A
      • LBL02A_RLS
      • LBL02B
    • Medical History
      • MHL01
    • Pharmacokinetic
      • ADAL01
      • PKCL01
      • PKCL02
      • PKPL01
      • PKPL02
      • PKPL04
    • Vital Signs
      • VSL01
  • Graphs
    • Efficacy
      • FSTG01
      • FSTG02
      • KMG01
      • MMRMG01
      • MMRMG02
    • Other
      • BRG01
      • BWG01
      • CIG01
      • IPPG01
      • LTG01
      • MNG01
    • Pharmacokinetic
      • PKCG01
      • PKCG02
      • PKCG03
      • PKPG01
      • PKPG02
      • PKPG03
      • PKPG04
      • PKPG06

  • Appendix
    • Reproducibility

  • Index

On this page

  • Output
  • Reproducibility
    • Timestamp
    • Session Info
    • .lock file
  • Edit this page
  • Report an issue
  1. Graphs
  2. Other
  3. BRG01

BRG01

Bar Chart


Output

  • Plot of Frequency
  • Plot of Percentage
  • Plot of Frequency with
    Total Number of Subjects
  • Plot of Frequency
    with Horizontal Bars
  • Plot of Percentage
    and Confidence Intervals
  • Plot of Percentage by
    Treatment and Covariate
  • Plot of Percentage by
    Covariate and Treatment
  • Plot of Percentage
    with Mean and Median
  • Plot of Categorical
    Variable
  • Data Setup
  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESER == "Y")
anl <- anl[!duplicated(anl$USUBJID), ]

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  geom_text(stat = "count", aes(label = ggplot2::after_stat(count)), vjust = -.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESOC == "cl A")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM) %>%
  summarise(n = n()) %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_col(aes(x = ACTARM, y = pct), fill = getOption("ggplot2.discrete.fill")[1]) +
  scale_y_continuous(labels = scales::comma) +
  geom_text(aes(y = pct, label = pct), stat = "identity", vjust = -0.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With cl A Disorders: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESOC == "cl A")
anl <- anl[!duplicated(anl$USUBJID), ]

anl <- anl %>%
  group_by(ACTARM) %>%
  mutate(n = n()) %>%
  mutate(xvarlabel = paste0(ACTARM, "\n\nN = ", n))

plot <- ggplot(anl, aes(x = .data[["xvarlabel"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESER == "Y")
anl <- anl[!duplicated(anl$USUBJID), ]

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency") +
  coord_flip()
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adlb %>%
  filter(PARAMCD == "ALT" & ANRIND == "HIGH")
anl <- anl[!duplicated(anl$USUBJID), ]

patpop5 <- as.data.frame(table(adsl$ACTARM)) %>%
  mutate(ACTARM = as.vector(Var1)) %>%
  mutate(TRTPOP = Freq) %>%
  select(ACTARM, TRTPOP)

anlpop <- as.data.frame(table(anl$ANRIND, anl$ACTARM)) %>%
  filter(Var1 == "HIGH") %>%
  mutate(ACTARM = as.vector(Var2)) %>%
  mutate(EVENTCOUNT = Freq) %>%
  select(ACTARM, EVENTCOUNT)

anl <- left_join(patpop5, anlpop, by = "ACTARM")
CIs <- binom.confint(x = anl$EVENTCOUNT, n = anl$TRTPOP, methods = "exact") 
anl <- cbind(anl, CIs[, 4:6])

plot <- ggplot(anl) +
  geom_bar(
    aes(x = ACTARM, y = mean * 100),
    stat = "identity",
    fill = getOption("ggplot2.discrete.fill")[1],
    alpha = 0.7
  ) +
  geom_errorbar(
    aes(x = ACTARM, ymin = lower * 100, ymax = upper * 100),
    width = 0.5,
    colour = "#20b4ff",
    alpha = 0.9,
    linewidth = 1.0
  ) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects with Abnormaly High ALT: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percentage")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESER == "Y")

patpop6 <- dplyr::count(adsl, ACTARM, SEX, name = "N_arm_sex")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM, SEX) %>%
  summarise(n = n(), .groups = "drop") %>%
  left_join(patpop6, by = c("ACTARM", "SEX")) %>%
  mutate(pct = round((n / N_arm_sex) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]], fill = .data[["SEX"]])) +
  geom_col(aes(y = pct), position = position_dodge()) +
  guides(fill = guide_legend(title = getElement(vl_ae, "SEX"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae %>%
  filter(AESER == "Y")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(SEX, ACTARM) %>%
  summarise(n = n(), .groups = "drop_last") %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["SEX"]], fill = .data[["ACTARM"]])) +
  geom_col(aes(y = pct), position = position_dodge()) +
  guides(fill = guide_legend(title = getElement(vl_ae, "ACTARM"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "SEX"), " (N = ", denom, ")")) +
  ylab("Percent")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl1 <- adlb %>%
  filter(AVISIT == "BASELINE", PARAMCD == "CRP" & ANRIND == "HIGH")

anl <- anl1[!duplicated(anl1$USUBJID), ] %>%
  group_by(ACTARM) %>%
  summarise(n = n()) %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

graph <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_col(aes(x = ACTARM, y = pct), fill = getOption("ggplot2.discrete.fill")[1]) +
  scale_y_continuous(labels = scales::comma, expand = expansion(c(0, .25))) +
  geom_text(aes(y = pct, label = pct), stat = "identity", vjust = -0.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects with Abnormaly High CRP at Baseline \n Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_lb, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")

sd_w <- anl1 %>%
  group_by(ACTARM) %>%
  summarise(
    mean = round(mean(AVAL, na.rm = TRUE), 2),
    median = round(median(AVAL, na.rm = TRUE), 2)
  ) %>%
  arrange(ACTARM)

sd_l <- gather(sd_w, key = stat, value = value, mean:median)
sd_l <- sd_l %>% mutate(
  stat_lbl = case_when(
    stat == "mean" ~ "Mean",
    stat == "median" ~ "Median"
  )
)

sd_l$stat_lbl <- factor(sd_l$stat_lbl, levels = c("Median", "Mean"))

tbl_theme <- theme(
  panel.border = element_blank(),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  axis.ticks = element_blank(),
  axis.title = element_blank(),
  axis.text.y = element_text(face = "plain"),
  axis.text.x = element_blank()
)

tbl <- ggplot(sd_l, aes(x = ACTARM, y = stat_lbl, label = value)) +
  geom_text(size = 3) +
  scale_y_discrete(labels = levels(sd_l$stat_lbl)) +
  theme_bw() +
  tbl_theme

plot <- cowplot::plot_grid(graph, tbl,
  rel_heights = c(4, 1),
  ncol = 1, nrow = 2, align = "v"
)
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

  • Preview
  • Try this using WebR
Code
anl <- adae

anl <- anl %>%
  arrange(USUBJID, AETOXGRC) %>%
  group_by(USUBJID) %>%
  slice(n()) %>%
  ungroup()

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM, AETOXGRC) %>%
  summarise(n = n(), .groups = "drop_last") %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]], fill = .data[["AETOXGRC"]])) +
  geom_col(aes(y = pct)) +
  guides(fill = guide_legend(title = getElement(vl_ae, "AETOXGRC"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With AE by Highest \n NCI CTCAE Grade: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot

Experimental use!

WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.

Code
library(binom)
library(dplyr)
library(ggplot2)
library(tidyr)
library(tern)
library(nestcolor)

adsl <- random.cdisc.data::cadsl

# filtered population
patpop_df <- adsl %>%
  group_by(STUDYID) %>%
  summarise(patpop = n())
patpop <- setNames(patpop_df$patpop, patpop_df$STUDYID)
denom <- patpop_df$patpop

adae <- random.cdisc.data::cadae %>%
  mutate(AETOXGRC = as.character(AETOXGR))
attributes(adae$AETOXGRC)$label <- "Analysis Toxicity Grade (C)"
vl_ae <- var_labels(adae)

adlb <- random.cdisc.data::cadlb
vl_lb <- var_labels(adlb)

Reproducibility

Timestamp

[1] "2025-07-05 18:02:34 UTC"

Session Info

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.0 (2025-04-11)
 os       Ubuntu 24.04.2 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Etc/UTC
 date     2025-07-05
 pandoc   3.7.0.2 @ /usr/bin/ (via rmarkdown)
 quarto   1.7.32 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package           * version date (UTC) lib source
 backports           1.5.0   2024-05-23 [1] RSPM
 binom             * 1.1-1.1 2022-05-02 [1] RSPM
 brio                1.1.5   2024-04-24 [1] RSPM
 broom               1.0.8   2025-03-28 [1] RSPM
 checkmate           2.3.2   2024-07-29 [1] RSPM
 cli                 3.6.5   2025-04-23 [1] RSPM
 codetools           0.2-20  2024-03-31 [2] CRAN (R 4.5.0)
 cowplot             1.1.3   2024-01-22 [1] RSPM
 curl                6.4.0   2025-06-22 [1] RSPM
 dichromat           2.0-0.1 2022-05-02 [1] CRAN (R 4.5.0)
 digest              0.6.37  2024-08-19 [1] RSPM
 dplyr             * 1.1.4   2023-11-17 [1] RSPM
 evaluate            1.0.4   2025-06-18 [1] RSPM
 farver              2.1.2   2024-05-13 [1] RSPM
 fastmap             1.2.0   2024-05-15 [1] RSPM
 formatters        * 0.5.11  2025-04-09 [1] RSPM
 generics            0.1.4   2025-05-09 [1] RSPM
 ggplot2           * 3.5.2   2025-04-09 [1] RSPM
 glue                1.8.0   2024-09-30 [1] RSPM
 gtable              0.3.6   2024-10-25 [1] RSPM
 htmltools           0.5.8.1 2024-04-04 [1] RSPM
 htmlwidgets         1.6.4   2023-12-06 [1] RSPM
 jsonlite            2.0.0   2025-03-27 [1] RSPM
 knitr               1.50    2025-03-16 [1] RSPM
 labeling            0.4.3   2023-08-29 [1] RSPM
 lattice             0.22-7  2025-04-02 [2] CRAN (R 4.5.0)
 lifecycle           1.0.4   2023-11-07 [1] RSPM
 magrittr          * 2.0.3   2022-03-30 [1] RSPM
 Matrix              1.7-3   2025-03-11 [1] CRAN (R 4.5.0)
 nestcolor         * 0.1.3   2025-01-21 [1] RSPM
 pillar              1.11.0  2025-07-04 [1] RSPM
 pkgcache            2.2.4   2025-05-26 [1] RSPM
 pkgconfig           2.0.3   2019-09-22 [1] RSPM
 processx            3.8.6   2025-02-21 [1] RSPM
 ps                  1.9.1   2025-04-12 [1] RSPM
 purrr               1.0.4   2025-02-05 [1] RSPM
 R6                  2.6.1   2025-02-15 [1] RSPM
 random.cdisc.data   0.3.16  2024-10-10 [1] RSPM
 rbibutils           2.3     2024-10-04 [1] RSPM
 RColorBrewer        1.1-3   2022-04-03 [1] RSPM
 Rdpack              2.6.4   2025-04-09 [1] RSPM
 rlang               1.1.6   2025-04-11 [1] RSPM
 rmarkdown           2.29    2024-11-04 [1] RSPM
 rtables           * 0.6.13  2025-06-19 [1] RSPM
 scales              1.4.0   2025-04-24 [1] RSPM
 sessioninfo         1.2.3   2025-02-05 [1] any (@1.2.3)
 stringi             1.8.7   2025-03-27 [1] RSPM
 stringr             1.5.1   2023-11-14 [1] RSPM
 survival            3.8-3   2024-12-17 [2] CRAN (R 4.5.0)
 tern              * 0.9.9   2025-06-20 [1] RSPM
 testthat            3.2.3   2025-01-13 [1] RSPM
 tibble              3.3.0   2025-06-08 [1] RSPM
 tidyr             * 1.3.1   2024-01-24 [1] RSPM
 tidyselect          1.2.1   2024-03-11 [1] RSPM
 vctrs               0.6.5   2023-12-01 [1] RSPM
 withr               3.0.2   2024-10-28 [1] RSPM
 xfun                0.52    2025-04-02 [1] RSPM
 yaml                2.3.10  2024-07-26 [1] RSPM

 [1] /usr/local/lib/R/site-library
 [2] /usr/local/lib/R/library
 [3] /github/home/R/x86_64-pc-linux-gnu-library/4.5
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────

.lock file

Download the .lock file and use renv::restore() on it to recreate environment used to generate this website.

Download

MMRMG02
BWG01
Source Code
---
title: BRG01
subtitle: Bar Chart
---

------------------------------------------------------------------------

{{< include ../../_utils/envir_hook.qmd >}}

```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(binom)
library(dplyr)
library(ggplot2)
library(tidyr)
library(tern)
library(nestcolor)

adsl <- random.cdisc.data::cadsl

# filtered population
patpop_df <- adsl %>%
  group_by(STUDYID) %>%
  summarise(patpop = n())
patpop <- setNames(patpop_df$patpop, patpop_df$STUDYID)
denom <- patpop_df$patpop

adae <- random.cdisc.data::cadae %>%
  mutate(AETOXGRC = as.character(AETOXGR))
attributes(adae$AETOXGRC)$label <- "Analysis Toxicity Grade (C)"
vl_ae <- var_labels(adae)

adlb <- random.cdisc.data::cadlb
vl_lb <- var_labels(adlb)
```

```{r include = FALSE}
webr_code_labels <- c("setup")
```

{{< include ../../_utils/webr_no_include.qmd >}}

## Output

:::::::::::: panel-tabset
## Plot of Frequency

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot1, test = list(plot_v1 = "plot")}
anl <- adae %>%
  filter(AESER == "Y")
anl <- anl[!duplicated(anl$USUBJID), ]

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  geom_text(stat = "count", aes(label = ggplot2::after_stat(count)), vjust = -.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot1")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Percentage

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot2, test = list(plot_v2 = "plot")}
anl <- adae %>%
  filter(AESOC == "cl A")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM) %>%
  summarise(n = n()) %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_col(aes(x = ACTARM, y = pct), fill = getOption("ggplot2.discrete.fill")[1]) +
  scale_y_continuous(labels = scales::comma) +
  geom_text(aes(y = pct, label = pct), stat = "identity", vjust = -0.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With cl A Disorders: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot2")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Frequency with <br/> Total Number of Subjects

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot3, test = list(plot_v3 = "plot")}
anl <- adae %>%
  filter(AESOC == "cl A")
anl <- anl[!duplicated(anl$USUBJID), ]

anl <- anl %>%
  group_by(ACTARM) %>%
  mutate(n = n()) %>%
  mutate(xvarlabel = paste0(ACTARM, "\n\nN = ", n))

plot <- ggplot(anl, aes(x = .data[["xvarlabel"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot3")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Frequency <br/> with Horizontal Bars

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot4, test = list(plot_v4 = "plot")}
anl <- adae %>%
  filter(AESER == "Y")
anl <- anl[!duplicated(anl$USUBJID), ]

plot <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_bar(fill = getOption("ggplot2.discrete.fill")[1]) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Frequency of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Frequency") +
  coord_flip()
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot4")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Percentage <br/> and Confidence Intervals

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of partial arg match in `bionom` https://github.com/cran/binom/blob/master/R/binom.confint.R#L31 -->

```{r plot5, test = list(plot_v5 = "plot"), opts.label = "skip_test_strict"}
anl <- adlb %>%
  filter(PARAMCD == "ALT" & ANRIND == "HIGH")
anl <- anl[!duplicated(anl$USUBJID), ]

patpop5 <- as.data.frame(table(adsl$ACTARM)) %>%
  mutate(ACTARM = as.vector(Var1)) %>%
  mutate(TRTPOP = Freq) %>%
  select(ACTARM, TRTPOP)

anlpop <- as.data.frame(table(anl$ANRIND, anl$ACTARM)) %>%
  filter(Var1 == "HIGH") %>%
  mutate(ACTARM = as.vector(Var2)) %>%
  mutate(EVENTCOUNT = Freq) %>%
  select(ACTARM, EVENTCOUNT)

anl <- left_join(patpop5, anlpop, by = "ACTARM")
CIs <- binom.confint(x = anl$EVENTCOUNT, n = anl$TRTPOP, methods = "exact") # nolint: object_name.
anl <- cbind(anl, CIs[, 4:6])

plot <- ggplot(anl) +
  geom_bar(
    aes(x = ACTARM, y = mean * 100),
    stat = "identity",
    fill = getOption("ggplot2.discrete.fill")[1],
    alpha = 0.7
  ) +
  geom_errorbar(
    aes(x = ACTARM, ymin = lower * 100, ymax = upper * 100),
    width = 0.5,
    colour = "#20b4ff",
    alpha = 0.9,
    linewidth = 1.0
  ) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects with Abnormaly High ALT: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percentage")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot5")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Percentage by <br/> Treatment and Covariate

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot6, test = list(plot_v6 = "plot")}
anl <- adae %>%
  filter(AESER == "Y")

patpop6 <- dplyr::count(adsl, ACTARM, SEX, name = "N_arm_sex")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM, SEX) %>%
  summarise(n = n(), .groups = "drop") %>%
  left_join(patpop6, by = c("ACTARM", "SEX")) %>%
  mutate(pct = round((n / N_arm_sex) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]], fill = .data[["SEX"]])) +
  geom_col(aes(y = pct), position = position_dodge()) +
  guides(fill = guide_legend(title = getElement(vl_ae, "SEX"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot6")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Percentage by <br/> Covariate and Treatment

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot7, test = list(plot_v7 = "plot")}
anl <- adae %>%
  filter(AESER == "Y")

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(SEX, ACTARM) %>%
  summarise(n = n(), .groups = "drop_last") %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["SEX"]], fill = .data[["ACTARM"]])) +
  geom_col(aes(y = pct), position = position_dodge()) +
  guides(fill = guide_legend(title = getElement(vl_ae, "ACTARM"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With Serious AEs: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "SEX"), " (N = ", denom, ")")) +
  ylab("Percent")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot7")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Percentage <br/> with Mean and Median

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot8, test = list(plot_v8 = "plot")}
anl1 <- adlb %>%
  filter(AVISIT == "BASELINE", PARAMCD == "CRP" & ANRIND == "HIGH")

anl <- anl1[!duplicated(anl1$USUBJID), ] %>%
  group_by(ACTARM) %>%
  summarise(n = n()) %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

graph <- ggplot(anl, aes(x = .data[["ACTARM"]])) +
  geom_col(aes(x = ACTARM, y = pct), fill = getOption("ggplot2.discrete.fill")[1]) +
  scale_y_continuous(labels = scales::comma, expand = expansion(c(0, .25))) +
  geom_text(aes(y = pct, label = pct), stat = "identity", vjust = -0.5) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects with Abnormaly High CRP at Baseline \n Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_lb, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")

sd_w <- anl1 %>%
  group_by(ACTARM) %>%
  summarise(
    mean = round(mean(AVAL, na.rm = TRUE), 2),
    median = round(median(AVAL, na.rm = TRUE), 2)
  ) %>%
  arrange(ACTARM)

sd_l <- gather(sd_w, key = stat, value = value, mean:median)
sd_l <- sd_l %>% mutate(
  stat_lbl = case_when(
    stat == "mean" ~ "Mean",
    stat == "median" ~ "Median"
  )
)

sd_l$stat_lbl <- factor(sd_l$stat_lbl, levels = c("Median", "Mean"))

tbl_theme <- theme(
  panel.border = element_blank(),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  axis.ticks = element_blank(),
  axis.title = element_blank(),
  axis.text.y = element_text(face = "plain"),
  axis.text.x = element_blank()
)

tbl <- ggplot(sd_l, aes(x = ACTARM, y = stat_lbl, label = value)) +
  geom_text(size = 3) +
  scale_y_discrete(labels = levels(sd_l$stat_lbl)) +
  theme_bw() +
  tbl_theme

plot <- cowplot::plot_grid(graph, tbl,
  rel_heights = c(4, 1),
  ncol = 1, nrow = 2, align = "v"
)
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot8")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Plot of Categorical <br/> Variable

::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview

```{r plot9, test = list(plot_v9 = "plot")}
anl <- adae

anl <- anl %>%
  arrange(USUBJID, AETOXGRC) %>%
  group_by(USUBJID) %>%
  slice(n()) %>%
  ungroup()

anl <- anl[!duplicated(anl$USUBJID), ] %>%
  group_by(ACTARM, AETOXGRC) %>%
  summarise(n = n(), .groups = "drop_last") %>%
  mutate(N = patpop) %>%
  mutate(N = as.numeric(N)) %>%
  mutate(pct = round((n / N) * 100, 2))

plot <- ggplot(anl, aes(x = .data[["ACTARM"]], fill = .data[["AETOXGRC"]])) +
  geom_col(aes(y = pct)) +
  guides(fill = guide_legend(title = getElement(vl_ae, "AETOXGRC"))) +
  scale_y_continuous(labels = scales::comma) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Percent of Subjects With AE by Highest \n NCI CTCAE Grade: Safety-Evaluable Subjects") +
  xlab(paste0(getElement(vl_ae, "ACTARM"), " (N = ", denom, ")")) +
  ylab("Percent")
plot
```

```{r include = FALSE}
webr_code_labels <- c("plot9")
```

{{< include ../../_utils/webr.qmd >}}
:::

## Data Setup

```{r setup}
#| code-fold: show
```
::::::::::::

{{< include ../../_utils/save_results.qmd >}}

{{< include ../../repro.qmd >}}

Made with ❤️ by the NEST Team

  • Edit this page
  • Report an issue
Cookie Preferences