Module is designed to explore the distribution of a single variable within a given dataset. It offers several tools, such as histograms, Q-Q plots, and various statistical tests to visually and statistically analyze the variable's distribution.
Usage
tm_g_distribution(
label = "Distribution Module",
dist_var,
strata_var = NULL,
group_var = NULL,
freq = FALSE,
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
ggplot2_args = teal.widgets::ggplot2_args(),
bins = c(30L, 1L, 100L),
plot_height = c(600, 200, 2000),
plot_width = NULL,
pre_output = NULL,
post_output = NULL,
transformators = list(),
decorators = list()
)
Arguments
- label
(
character(1)
) Label shown in the navigation item for the module or module group. Formodules()
defaults to"root"
. SeeDetails
.- dist_var
(
data_extract_spec
orlist
of multipledata_extract_spec
) Variable(s) for which the distribution will be analyzed.- strata_var
(
data_extract_spec
orlist
of multipledata_extract_spec
) Categorical variable used to split the distribution analysis.- group_var
(
data_extract_spec
orlist
of multipledata_extract_spec
) Variable used for faceting plot into multiple panels.- freq
(
logical
) optional, whether to display frequency (TRUE
) or density (FALSE
). Defaults to density (FALSE
).- ggtheme
(
character
) optional,ggplot2
theme to be used by default. Defaults to"gray"
.- ggplot2_args
-
(
ggplot2_args
) optional, object created byteal.widgets::ggplot2_args()
with settings for all the plots or named list ofggplot2_args
objects for plot-specific settings. The argument is merged with options variableteal.ggplot2_args
and default module setup.List names should match the following:
c("default", "Histogram", "QQplot")
.For more details see the vignette:
vignette("custom-ggplot2-arguments", package = "teal.widgets")
. - bins
-
(
integer(1)
orinteger(3)
) optional, specifies the number of bins for the histogram.When the length of
bins
is one: The histogram bins will have a fixed size based on thebins
provided.When the length of
bins
is three: The histogram bins are dynamically adjusted based on vector ofvalue
,min
, andmax
. Defaults toc(30L, 1L, 100L)
.
- plot_height
(
numeric
) optional, specifies the plot height as a three-element vector ofvalue
,min
, andmax
intended for use with a slider UI element.- plot_width
(
numeric
) optional, specifies the plot width as a three-element vector ofvalue
,min
, andmax
for a slider encoding the plot width.- pre_output
(
shiny.tag
) optional,
with text placed before the output to put the output into context. For example a title.- post_output
(
shiny.tag
) optional, with text placed after the output to put the output into context. For example theshiny::helpText()
elements are useful.- transformators
(
list
ofteal_transform_module
) that will be applied to transform module's data input. To learn more checkvignette("data-transform-as-shiny-module", package = "teal")
.- decorators
-
(
list
ofteal_transform_module
, namedlist
ofteal_transform_module
) optional, decorator for tables or plots included in the module output reported. When a named list ofteal_transform_module
, the decorators are applied to the respective output objects.Otherwise, the decorators are applied to all objects, which is equivalent as using the name
default
.See section "Decorating Module" below for more details.
Decorating Module
This module generates the following objects, which can be modified in place using decorators::
histogram_plot
(ggplot2
)qq_plot
(ggplot2
)summary_table
(listing_df
created withrlistings::as_listing()
)test_table
(listing_df
created withrlistings::as_listing()
)
Decorators can be applied to all outputs or only to specific objects using a
named list of teal_transform_module
objects.
The "default"
name is reserved for decorators that are applied to all outputs.
See code snippet below:
tm_g_distribution(
..., # arguments for module
decorators = list(
default = list(teal_transform_module(...)), # applied to all outputs
histogram_plot = list(teal_transform_module(...)), # applied only to `histogram_plot` output
qq_plot = list(teal_transform_module(...)) # applied only to `qq_plot` output
summary_table = list(teal_transform_module(...)) # applied only to `summary_table` output
test_table = list(teal_transform_module(...)) # applied only to `test_table` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-modules-output", package = "teal")
or the teal::teal_transform_module()
documentation.
Examples
# general data example
data <- teal_data()
data <- within(data, {
iris <- iris
})
app <- init(
data = data,
modules = list(
tm_g_distribution(
dist_var = data_extract_spec(
dataname = "iris",
select = select_spec(variable_choices("iris"), "Petal.Length")
)
)
)
)
#> Initializing tm_g_distribution
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- teal_data()
data <- within(data, {
ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]
vars1 <- choices_selected(
variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
selected = NULL
)
app <- init(
data = data,
modules = modules(
tm_g_distribution(
dist_var = data_extract_spec(
dataname = "ADSL",
select = select_spec(
choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
selected = "BMRKR1",
multiple = FALSE,
fixed = FALSE
)
),
strata_var = data_extract_spec(
dataname = "ADSL",
filter = filter_spec(
vars = vars1,
multiple = TRUE
)
),
group_var = data_extract_spec(
dataname = "ADSL",
filter = filter_spec(
vars = vars1,
multiple = TRUE
)
)
)
)
)
#> Initializing tm_g_distribution
if (interactive()) {
shinyApp(app$ui, app$server)
}