Skip to content

Commit 1a46c7f

Browse files
authored
Merge pull request #118 from Merck/Add-example-of-long-treatment-labels
Add example of long treatment labels
2 parents 5cf3161 + 3e8f1c8 commit 1a46c7f

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
- uses: r-lib/actions/setup-r-dependencies@v2
2525
with:
26-
extra-packages: any::covr
26+
extra-packages: any::covr, any::xml2
2727
needs: coverage
2828

2929
- name: Test coverage

R/format_ae_forestly.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ format_ae_forestly <- function(
253253
columnGroups <- list()
254254
for (i in 1:m_group) {
255255
columnGroups[[i]] <- reactable::colGroup(
256-
name = paste0(outdata$group[i], "<br> (N=", outdata$n_pop[i], ")"),
256+
name = paste0(
257+
'<span title="',
258+
paste0(outdata$group[i], " (N=", outdata$n_pop[i], ")"),
259+
'">',
260+
paste0(outdata$group[i], "<br> (N=", outdata$n_pop[i], ")"),
261+
'</span>'
262+
),
257263
html = TRUE,
258264
columns = c(name_n[i], name_prop[i])
259265
)

vignettes/customize-width.Rmd

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ knitr::opts_chunk$set(
2424
```{r}
2525
library(forestly)
2626
library(metalite)
27+
library(dplyr)
2728
```
2829

2930
The interactive AE forest plots include AE-specific tables presenting numerical values for AE proportions, differences, and confidence intervals (CI), alongside their visualizations. Each type of information is displayed in a separate column. In this vignette, we demonstrate how to customize the column widths in these tables.
3031

31-
# Step 1: build your metadata
32+
# General Use
33+
34+
## Step 1: build your metadata
3235

3336
Building interactive AE forest plots starts with constructing the metadata. The detailed procedure for building metadata is covered in the vignette [Generate Interactive AE Forest Plots with Drill Down to AE Listing](https://merck.github.io/forestly/articles/forestly.html). Therefore, in this vignette, we will skip those details and directly use the metadata created there.
3437

@@ -77,7 +80,7 @@ meta <- meta_adam(population = adsl, observation = adae) |>
7780
```
7881

7982

80-
# Step 2: adjusting column widths
83+
## Step 2: adjusting column widths
8184

8285
Users can control the column widths using the following arguments:
8386

@@ -106,3 +109,96 @@ meta |>
106109
) |>
107110
ae_forestly()
108111
```
112+
113+
# Multiple, Long Treatment Labels Example
114+
115+
## Step 1: build example metadata
116+
117+
The datasets used here include five treatment arms with long labels.
118+
119+
```{r}
120+
adsl <- forestly_adsl
121+
adae <- forestly_adae
122+
123+
set.seed(1234)
124+
adsl$TRTA <- sample(
125+
x = c("Control Arm A",
126+
"Control Arm B",
127+
"Active Arm (Mono): Drug X",
128+
"Active Arm (Comb): Drug X + Drug A + Drug B + Drug C",
129+
"Active Arm: Cumulative Drug X"),
130+
size = nrow(adsl),
131+
replace = TRUE
132+
)
133+
adae <- adae |>
134+
dplyr::select(-TRTA) |>
135+
dplyr::left_join(
136+
adsl,
137+
by = c("USUBJID"),
138+
suffix = c("", ".y")
139+
) |>
140+
dplyr::select(-ends_with(".y"))
141+
142+
adsl$TRTA <- factor(
143+
adsl$TRTA,
144+
levels = c("Active Arm: Cumulative Drug X",
145+
"Active Arm (Mono): Drug X",
146+
"Active Arm (Comb): Drug X + Drug A + Drug B + Drug C",
147+
"Control Arm A",
148+
"Control Arm B")
149+
)
150+
adae$TRTA <- factor(
151+
adae$TRTA,
152+
levels = c("Active Arm: Cumulative Drug X",
153+
"Active Arm (Mono): Drug X",
154+
"Active Arm (Comb): Drug X + Drug A + Drug B + Drug C",
155+
"Control Arm A",
156+
"Control Arm B")
157+
)
158+
159+
meta <- meta_adam(population = adsl, observation = adae) |>
160+
define_plan(plan = plan(
161+
analysis = "ae_forestly",
162+
population = "apat",
163+
observation = "apat",
164+
parameter = "any;drug-related"
165+
)) |>
166+
define_analysis(name = "ae_forestly", label = "Interactive Forest Plot") |>
167+
define_population(
168+
name = "apat", group = "TRTA", id = "USUBJID",
169+
subset = SAFFL == "Y", label = "All Patient as Treated"
170+
) |>
171+
define_observation(
172+
name = "apat", group = "TRTA",
173+
subset = SAFFL == "Y", label = "All Patient as Treated"
174+
) |>
175+
define_parameter(
176+
name = "any",
177+
subset = NULL,
178+
label = "Any AEs",
179+
var = "AEDECOD", soc = "AEBODSYS"
180+
) |>
181+
define_parameter(
182+
name = "drug-related",
183+
subset = toupper(AREL) == "RELATED",
184+
label = "Drug-related AEs",
185+
var = "AEDECOD", soc = "AEBODSYS"
186+
) |>
187+
meta_build()
188+
```
189+
190+
## Step 2: adjusting column widths
191+
192+
In this example, we adjust the column widths to accommodate the long treatment labels and multiple treatment arms. To ensure sufficient space for the legend, the `width_fig` is set to a larger value and the `footer_space` is increased.
193+
194+
```{r}
195+
meta |>
196+
prepare_ae_forestly() |>
197+
format_ae_forestly(
198+
footer_space = 210,
199+
width_fig = 420,
200+
display = c("n", "prop", "fig_prop", "fig_diff", "diff"),
201+
color = c("#66203A", "#00857C", "#6ECEB2", "#BFED33", "#DFEd31")
202+
) |>
203+
ae_forestly()
204+
```

0 commit comments

Comments
 (0)