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 = list(teal.picks::picks(teal.picks::datasets(),
teal.picks::variables(selected = seq(1L, 5L), multiple = TRUE))),
min_n_variables = 2L,
max_n_variables = 5L,
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 (ggplot - a patchwork assembled from individual ggplot panels)
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.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
For more examples, please see the vignette "Using scatterplot matrix" via
vignette("using-scatterplot-matrix", package = "teal.modules.general").
When Add Correlation is enabled, a simple Omit NAs checkbox
controls NA handling (checked = "pairwise.complete.obs", matching the
historical default). Unchecking it reveals a dropdown with all five
stats::cor() use options for advanced control.
# 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(
teal.picks::picks(
datasets("countries"),
teal.picks::variables(
choices = tidyselect::everything(),
selected = c("area", "gdp", "debt"),
multiple = TRUE,
ordered = TRUE
),
teal.picks::values()
),
teal.picks::picks(
datasets("sales"),
teal.picks::variables(
choices = c("quantity", "costs", "profit"),
selected = c("quantity", "costs"),
multiple = TRUE,
ordered = TRUE
)
)
),
transformators = list(
teal_transform_filter(
teal.picks::picks(
datasets("sales"),
teal.picks::variables("country_id"),
teal.picks::values()
)
)
)
)
)
)
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(
teal.picks::picks(
datasets("ADSL"),
teal.picks::variables(
choices = tidyselect::everything(),
selected = c("AGE", "RACE", "SEX"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
),
teal.picks::values()
),
teal.picks::picks(
datasets("ADRS"),
teal.picks::variables(
choices = tidyselect::everything(),
selected = c("AVAL", "ADY"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
)
),
transformators = list(
teal_transform_filter(
teal.picks::picks(
teal.picks::datasets("ADRS"),
teal.picks::variables("PARAMCD"),
teal.picks::values(selected = "BESRSPI")
)
)
)
)
)
)
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.