View source: R/tm_g_scatterplotmatrix.R
tm_g_scatterplotmatrix | R Documentation |
teal
module: Scatterplot matrixGenerates 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.
tm_g_scatterplotmatrix(
label = "Scatterplot Matrix",
variables,
plot_height = c(600, 200, 2000),
plot_width = NULL,
pre_output = NULL,
post_output = NULL,
transformators = list(),
decorators = list()
)
Object of class teal_module
to be used in teal
applications.
This module generates the following objects, which can be modified in place using decorators:
plot
(trellis
- output of lattice::splom
)
A Decorator is applied to the specific output using a named list of teal_transform_module
objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_scatterplotmatrix( ..., # arguments for module decorators = list( plot = teal_transform_module(...) # applied to the `plot` output ) )
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.modules.general")
.
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal")
or the teal::teal_transform_module()
documentation.
For more examples, please see the vignette "Using scatterplot matrix" via
vignette("using-scatterplot-matrix", package = "teal.modules.general")
.
# 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", "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
)
)
)
)
)
)
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
)
)
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.