Generates a scatterplot matrix from selected variables
from datasets.
Each plot within the matrix represents the relationship between two variables,
providing the overview of correlations and distributions across selected data.
Usage
tm_g_scatterplotmatrix(
label = "Scatterplot Matrix",
variables,
plot_height = c(600, 200, 2000),
plot_width = NULL,
pre_output = NULL,
post_output = NULL,
decorators = NULL
)
Arguments
- label
(
character(1)
) Label shown in the navigation item for the module or module group. Formodules()
defaults to"root"
. SeeDetails
.- variables
(
data_extract_spec
orlist
of multipledata_extract_spec
) Specifies plotting variables from an incoming dataset with filtering and selecting. In case ofdata_extract_spec
useselect_spec(..., ordered = TRUE)
if plot elements should be rendered according to selection order.- 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, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.- post_output
(
shiny.tag
) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements likeshiny::helpText()
are useful.- decorators
-
(
list
ofteal_transform_module
, namedlist
ofteal_transform_module
orNULL
) optional, if notNULL
, decorator for tables or plots included in the module. 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
tm_g_scatterplotmatrix
" below for more details.
Note
For more examples, please see the vignette "Using scatterplot matrix" via
vignette("using-scatterplot-matrix", package = "teal.modules.general")
.
Decorating tm_g_scatterplotmatrix
This module generates the following objects, which can be modified in place using decorators:
plot
(trellis
- output oflattice::splom
)
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, {
countries <- data.frame(
id = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"),
government = factor(
c(2, 2, 2, 1, 2, 2, 1, 1, 1, 2),
labels = c("Monarchy", "Republic")
),
language_family = factor(
c(1, 3, 3, 3, 3, 2, 1, 1, 3, 1),
labels = c("Germanic", "Hellenic", "Romance")
),
population = c(83, 67, 60, 47, 10, 11, 17, 11, 0.6, 9),
area = c(357, 551, 301, 505, 92, 132, 41, 30, 2.6, 83),
gdp = c(3.4, 2.7, 2.1, 1.4, 0.3, 0.2, 0.7, 0.5, 0.1, 0.4),
debt = c(2.1, 2.3, 2.4, 2.6, 2.3, 2.4, 2.3, 2.4, 2.3, 2.4)
)
sales <- data.frame(
id = 1:50,
country_id = sample(
c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"),
size = 50,
replace = TRUE
),
year = sort(sample(2010:2020, 50, replace = TRUE)),
venue = sample(c("small", "medium", "large", "online"), 50, replace = TRUE),
cancelled = sample(c(TRUE, FALSE), 50, replace = TRUE),
quantity = rnorm(50, 100, 20),
costs = rnorm(50, 80, 20),
profit = rnorm(50, 20, 10)
)
})
join_keys(data) <- join_keys(
join_key("countries", "countries", "id"),
join_key("sales", "sales", "id"),
join_key("countries", "sales", c("id" = "country_id"))
)
app <- init(
data = data,
modules = modules(
tm_g_scatterplotmatrix(
label = "Scatterplot matrix",
variables = list(
data_extract_spec(
dataname = "countries",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["countries"]]),
selected = c("area", "gdp", "debt"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
),
data_extract_spec(
dataname = "sales",
filter = filter_spec(
label = "Select variable:",
vars = "country_id",
choices = value_choices(data[["sales"]], "country_id"),
selected = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"),
multiple = TRUE
),
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["sales"]], c("quantity", "costs", "profit")),
selected = c("quantity", "costs", "profit"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
)
)
)
)
)
#> Initializing tm_g_scatterplotmatrix
#> Initializing reporter_previewer_module
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- teal_data()
data <- within(data, {
ADSL <- teal.data::rADSL
ADRS <- teal.data::rADRS
})
join_keys(data) <- default_cdisc_join_keys[names(data)]
app <- init(
data = data,
modules = modules(
tm_g_scatterplotmatrix(
label = "Scatterplot matrix",
variables = list(
data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADSL"]]),
selected = c("AGE", "RACE", "SEX"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
),
data_extract_spec(
dataname = "ADRS",
filter = filter_spec(
label = "Select endpoints:",
vars = c("PARAMCD", "AVISIT"),
choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")),
selected = "INVET - END OF INDUCTION",
multiple = TRUE
),
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADRS"]]),
selected = c("AGE", "AVAL", "ADY"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
)
)
)
)
)
#> Initializing tm_g_scatterplotmatrix
#> Initializing reporter_previewer_module
if (interactive()) {
shinyApp(app$ui, app$server)
}