Title: | Interactive Forest Plot |
---|---|
Description: | Interactive forest plot for clinical trial safety analysis using 'metalite', 'reactable', 'plotly', and Analysis Data Model (ADaM) datasets. Includes functionality for adverse event filtering, incidence-based group filtering, hover-over reveals, and search and sort operations. The workflow allows for metadata construction, data preparation, output formatting, and interactive plot generation. |
Authors: | Yilong Zhang [aut], Benjamin Wang [aut, cre], Yujie Zhao [aut], Nan Xiao [ctb], Hiroaki Fukuda [ctb], Yulia Sidi [ctb], Xuan Deng [ctb], Merck & Co., Inc., Rahway, NJ, USA and its affiliates [cph] |
Maintainer: | Benjamin Wang <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2024-11-15 03:06:23 UTC |
Source: | https://github.com/merck/forestly |
Display interactive forest plot
ae_forestly( outdata, display_soc_toggle = TRUE, filter = c("prop", "n"), width = 1400, max_page = NULL )
ae_forestly( outdata, display_soc_toggle = TRUE, filter = c("prop", "n"), width = 1400, max_page = NULL )
outdata |
An |
display_soc_toggle |
A boolean value to display SOC toggle button. |
filter |
A character value of the filter variable. |
width |
A numeric value of width of the table in pixels. |
max_page |
A numeric value of max page number shown in the table. |
An AE forest plot saved as a shiny.tag.list
object.
adsl <- forestly_adsl[1:100, ] adae <- forestly_adae[1:100, ] if (interactive()) { meta_forestly( dataset_adsl = adsl, dataset_adae = adae, ) |> prepare_ae_forestly() |> format_ae_forestly() |> ae_forestly() }
adsl <- forestly_adsl[1:100, ] adae <- forestly_adae[1:100, ] if (interactive()) { meta_forestly( dataset_adsl = adsl, dataset_adae = adae, ) |> prepare_ae_forestly() |> format_ae_forestly() |> ae_forestly() }
Creates colored background for panels of rainfall or forest plot.
background_panel( g, background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3 )
background_panel( g, background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3 )
g |
A ggplot object for adding colored background. |
background_color |
A vector of colors that defines the color for the plot background. Default is c("#69B8F7", "#FFFFFF"), which are pastel blue and white. The colors will be recycled. |
background_alpha |
Opacity of a geom. Default is 0.3. |
Plot as a colored background to add panels for rainfall or forest plot.
library(ggplot2) df <- data.frame( study = c("S1", "S2", "S3", "S4", "S5", "S6", "S7"), item = as.factor(1:7), effect = c(-.4, -.25, -.1, .1, .15, .2, .3), lower = c(-.43, -.29, -.17, -.02, .04, .17, .27), upper = c(-.37, -.21, -.03, .22, .24, .23, .33) ) ggplot(data = df) |> background_panel(background_color = c("grey", "white"), background_alpha = 0.4) + geom_point(aes(y = item, x = effect)) + geom_errorbar(aes(y = item, x = effect, xmin = lower, xmax = upper), width = 0.4) + scale_y_discrete(name = "", breaks = 1:nrow(df), labels = df$study)
library(ggplot2) df <- data.frame( study = c("S1", "S2", "S3", "S4", "S5", "S6", "S7"), item = as.factor(1:7), effect = c(-.4, -.25, -.1, .1, .15, .2, .3), lower = c(-.43, -.29, -.17, -.02, .04, .17, .27), upper = c(-.37, -.21, -.03, .22, .24, .23, .33) ) ggplot(data = df) |> background_panel(background_color = c("grey", "white"), background_alpha = 0.4) + geom_point(aes(y = item, x = effect)) + geom_errorbar(aes(y = item, x = effect, xmin = lower, xmax = upper), width = 0.4) + scale_y_discrete(name = "", breaks = 1:nrow(df), labels = df$study)
A dataset containing the adverse event information of a clinical trial following the CDISC ADaM standard.
forestly_adae
forestly_adae
A data frame with 736 rows and 56 variables.
Definition of each variable can be found at https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc.
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
A dataset containing the adverse event information of a clinical trial following the CDISC ADaM standard.
forestly_adae_3grp
forestly_adae_3grp
A data frame with 1191 rows and 56 variables.
Definition of each variable can be found at https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc.
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
A dataset containing the demographic information of a clinical trial following the CDISC ADaM standard.
forestly_adsl
forestly_adsl
A data frame with 170 rows and 49 variables.
Definition of each variable can be found at https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc.
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
A dataset containing the demographic information of a clinical trial following the CDISC ADaM standard.
forestly_adsl_3grp
forestly_adsl_3grp
A data frame with 254 rows and 49 variables.
Definition of each variable can be found at https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc.
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
Format outdata for interactive forest plot
format_ae_forestly( outdata, display = c("n", "prop", "fig_prop", "fig_diff"), digits = 1, width_term = 200, width_fig = 320, width_n = 40, width_prop = 60, width_diff = 80, footer_space = 90, color = NULL, diff_label = "Treatment <- Favor -> Placebo", show_ae_parameter = FALSE )
format_ae_forestly( outdata, display = c("n", "prop", "fig_prop", "fig_diff"), digits = 1, width_term = 200, width_fig = 320, width_n = 40, width_prop = 60, width_diff = 80, footer_space = 90, color = NULL, diff_label = "Treatment <- Favor -> Placebo", show_ae_parameter = FALSE )
outdata |
An |
display |
A character vector of measurement to be displayed.
|
digits |
A value of digits to be displayed for proportion and risk difference. |
width_term |
Width in px for AE term column. |
width_fig |
Width in px for proportion and risk difference figure. |
width_n |
Width in px for "N" columns. |
width_prop |
Width in px for "(%)" columns. |
width_diff |
Width in px for risk difference columns. |
footer_space |
Space in px for footer to display legend. |
color |
A vector of colors for analysis groups. Default value supports up to 4 groups. |
diff_label |
x-axis label for risk difference. |
show_ae_parameter |
A boolean value to display AE parameter column. |
An outdata
object.
adsl <- forestly_adsl[1:100,] adae <- forestly_adae[1:100,] meta_forestly( dataset_adsl = adsl, dataset_adae = adae ) |> prepare_ae_forestly()|> format_ae_forestly()
adsl <- forestly_adsl[1:100,] adae <- forestly_adae[1:100,] meta_forestly( dataset_adsl = adsl, dataset_adae = adae ) |> prepare_ae_forestly()|> format_ae_forestly()
Create metadata for interactive forest plot
meta_forestly( dataset_adsl, dataset_adae, population_term = "apat", observation_term = "safety", parameter_term = "any;rel", population_subset, observation_subset, treatment_group = "TRTA" )
meta_forestly( dataset_adsl, dataset_adae, population_term = "apat", observation_term = "safety", parameter_term = "any;rel", population_subset, observation_subset, treatment_group = "TRTA" )
dataset_adsl |
ADSL source dataset. |
dataset_adae |
ADAE source dataset. |
population_term |
A character value of population term name. |
observation_term |
A character value of observation term name. |
parameter_term |
A character value of parameter term name. |
population_subset |
An unquoted condition for selecting the populations from ADSL dataset. |
observation_subset |
An unquoted condition for selecting the observations from ADAE dataset. |
treatment_group |
A character value of treatment group name. |
A metalite object.
meta_forestly( forestly_adsl, forestly_adae, population_term = "apat", observation_term = "safety", parameter_term = "any;rel" )
meta_forestly( forestly_adsl, forestly_adae, population_term = "apat", observation_term = "safety", parameter_term = "any;rel" )
Create a dot plot by item. For instance, this could be used to create AEs incidence plot by Preferred Term and treatment group, as part of a rainfall plot.
plot_dot( tbl, y_var, label, x_breaks = NULL, color = NULL, shape = NULL, title = "AE (%)", background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3, theme = theme_panel(show_text = TRUE, show_ticks = TRUE), legend_nrow = 1 )
plot_dot( tbl, y_var, label, x_breaks = NULL, color = NULL, shape = NULL, title = "AE (%)", background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3, theme = theme_panel(show_text = TRUE, show_ticks = TRUE), legend_nrow = 1 )
tbl |
A data frame selected from input data set to display on this plot. y and x variables are required. |
y_var |
A character string that specifies a variable to be displayed on the y-axis. |
label |
A character vector of labels for each treatment group. The control group label should be specified as the last element of the vector. |
x_breaks |
A numeric vector for x-axis breaks. Default is |
color |
Color for each treatment group. |
shape |
Shape for each treatment group. Default is circle and square. Input values could be either a character or numeric value, For details, see https://ggplot2.tidyverse.org/articles/ggplot2-specs.html. |
title |
Panel title. Default is |
background_color |
Plot background color. Default is
|
background_alpha |
Opacity of the background. Default is 0.3.
The value of this argument is the input for |
theme |
Panel theme, including the y-axis text, ticks, and plot margin.
Default is |
legend_nrow |
Integer, the number of rows for a legend display.
Must be smaller than or equal to the number of the treatment groups.
To omit the legend, set this to |
AEs incidence plot by item and treatment group.
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, prop_1, prop_2) |> plot_dot("name", label = c("Treatment", "Placebo"))
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, prop_1, prop_2) |> plot_dot("name", label = c("Treatment", "Placebo"))
Create a plot to display risk difference for each item.
plot_errorbar( tbl, y_var, errbar_width = 0.4, color = NULL, shape = NULL, label, x_breaks = NULL, grp_abbrev = "paired", favor_direction = "negative", vline = NULL, line_type = 1, title = "Risk Diff. + 95% CI \n (Percentage Points)", background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3, theme = theme_panel(show_text = TRUE, show_ticks = TRUE), legend_nrow = 1 )
plot_errorbar( tbl, y_var, errbar_width = 0.4, color = NULL, shape = NULL, label, x_breaks = NULL, grp_abbrev = "paired", favor_direction = "negative", vline = NULL, line_type = 1, title = "Risk Diff. + 95% CI \n (Percentage Points)", background_color = c("#69B8F7", "#FFFFFF"), background_alpha = 0.3, theme = theme_panel(show_text = TRUE, show_ticks = TRUE), legend_nrow = 1 )
tbl |
A data frame selected from input data set to display on this plot. y and x variables are required. |
y_var |
A character string that specifies a variable to be displayed on the y-axis. |
errbar_width |
A numeric value to define the error bar width.
Default is 0.4. Value of this argument will be a half length of the
error bar, for example, |
color |
Color for each treatment group. |
shape |
Shape for each treatment group. Default is circle and square. Input values could be either a character or numeric value, For details, see https://ggplot2.tidyverse.org/articles/ggplot2-specs.html. |
label |
A character vector of labels for each treatment group. The control group label should be specified as the last element of the vector. |
x_breaks |
A numeric vector for x-axis breaks. Default is |
grp_abbrev |
A character vector for displaying the treatment groups
on a favor bar.
If |
favor_direction |
The position of a favor label under the condition
"comparison is treatment – control". For AEs, |
vline |
Vertical reference line position. Default is |
line_type |
Reference line type. Default is solid line.
Users can define one or multiple line types in a vector
(can be numeric such as 1, 2, 3 or character such as |
title |
Plot title. Default is |
background_color |
Plot background color. Default is
|
background_alpha |
Opacity of the background. Default is 0.3.
The value of this argument is the input for |
theme |
Panel theme, including the y-axis text, ticks, and plot margin.
Default is |
legend_nrow |
Integer, the number of rows for a legend display.
Must be smaller than or equal to the number of the treatment groups.
To omit the legend, set this to |
A risk difference plot for each item.
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, diff_1, lower_1, upper_1) |> plot_errorbar( y_var = "name", label = c("Treatment", "Placebo") )
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, diff_1, lower_1, upper_1) |> plot_errorbar( y_var = "name", label = c("Treatment", "Placebo") )
Prepare datasets for interactive forest plot
prepare_ae_forestly( meta, population = NULL, observation = NULL, parameter = NULL, components = "par", reference_group = NULL, ae_listing_display = c("USUBJID", "SITEID", "SEX", "RACE", "AGE", "ASTDY", "AESER", "AEREL", "AEACN", "AEOUT", "ADURN", "ADURU"), ae_listing_unique = FALSE )
prepare_ae_forestly( meta, population = NULL, observation = NULL, parameter = NULL, components = "par", reference_group = NULL, ae_listing_display = c("USUBJID", "SITEID", "SEX", "RACE", "AGE", "ASTDY", "AESER", "AEREL", "AEACN", "AEOUT", "ADURN", "ADURU"), ae_listing_unique = FALSE )
meta |
A metadata object created by metalite. |
population |
A character value of population term name. The term name is used as key to link information. |
observation |
A character value of observation term name. The term name is used as key to link information. |
parameter |
A character value of parameter term name. The term name is used as key to link information. |
components |
A character vector of components name. |
reference_group |
An integer to indicate reference group. Default is 2 if there are 2 groups, otherwise, the default is 1. |
ae_listing_display |
A vector of name of variables used to display on AE listing table. |
ae_listing_unique |
A logical value to display only unique records on AE listing table. |
An outdata
object.
adsl <- forestly_adsl[1:100,] adae <- forestly_adae[1:100,] meta_forestly( dataset_adsl = adsl, dataset_adae = adae ) |> prepare_ae_forestly()
adsl <- forestly_adsl[1:100,] adae <- forestly_adae[1:100,] meta_forestly( dataset_adsl = adsl, dataset_adae = adae ) |> prepare_ae_forestly()
Creates a table panel ggplot2 object for rainfall or forest plot.
table_panel( tbl, y_var, x_label = NULL, text_color = NULL, text_size = 8, text_format_by = "column", background_color = c("#69B8F7", "#FFFFFF"), theme = theme_panel(show_ticks = TRUE, show_text = TRUE), background_alpha = 0.3 )
table_panel( tbl, y_var, x_label = NULL, text_color = NULL, text_size = 8, text_format_by = "column", background_color = c("#69B8F7", "#FFFFFF"), theme = theme_panel(show_ticks = TRUE, show_text = TRUE), background_alpha = 0.3 )
tbl |
A data frame to be displayed in this table. |
y_var |
A string of a variable name from |
x_label |
Labels displayed on the top of table for each column of table.
Default is |
text_color |
Defines colors to display each treatment group. |
text_size |
Numeric font size for data on each column. Default is 8 for each column. |
text_format_by |
An option for formatting a data by columns or rows.
Default is |
background_color |
Color for the plot background.
Default is |
theme |
Controls display of y axis text, ticks and plot margin.
By default, |
background_alpha |
Opacity of the background. Default is 0.3.
The value of this argument will be the input value for the
|
A ggplot2 object for table panel.
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, diff_1, lower_1, upper_1) |> table_panel(y_var = "name")
forestly_adsl$TRTA <- factor( forestly_adsl$TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) forestly_adae$TRTA <- factor( forestly_adae$TRTA, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo") ) meta <- meta_forestly( dataset_adsl = forestly_adsl, dataset_adae = forestly_adae, population_term = "apat", observation_term = "wk12", parameter_term = "any;rel;ser" ) |> prepare_ae_forestly() |> format_ae_forestly() meta_any <- meta$tbl[1:20, ] |> dplyr::filter(parameter == "any") meta_any |> dplyr::select(name, diff_1, lower_1, upper_1) |> table_panel(y_var = "name")
Specifies theme for a plot with multiple panels.
theme_panel(show_text = TRUE, show_ticks = TRUE)
theme_panel(show_text = TRUE, show_ticks = TRUE)
show_text |
A logical value that controls text display on the y axis.
Default is |
show_ticks |
A logical value that controls ticks display on the y axis.
Default is |
Theme for a specific panel.
library(ggplot2) p <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() p p + theme_panel()
library(ggplot2) p <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() p p + theme_panel()