tm_g_response {teal.modules.general} | R Documentation |
teal
module: Response plot
Description
Generates a response plot for a given response
and x
variables.
This module allows users customize and add annotations to the plot depending
on the module's arguments.
It supports showing the counts grouped by other variable facets (by row / column),
swapping the coordinates, show count annotations and displaying the response plot
as frequency or density.
Usage
tm_g_response(
label = "Response Plot",
response,
x,
row_facet = NULL,
col_facet = NULL,
coord_flip = FALSE,
count_labels = TRUE,
rotate_xaxis_labels = FALSE,
freq = FALSE,
plot_height = c(600, 400, 5000),
plot_width = NULL,
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL
)
Arguments
label |
( |
response |
( The |
x |
( The |
row_facet |
( |
col_facet |
( |
coord_flip |
( |
count_labels |
( |
rotate_xaxis_labels |
( |
freq |
( |
plot_height |
( |
plot_width |
( |
ggtheme |
( |
ggplot2_args |
( For more details see the vignette: |
pre_output |
( |
post_output |
( |
Value
Object of class teal_module
to be used in teal
applications.
Note
For more examples, please see the vignette "Using response plot" via
vignette("using-response-plot", package = "teal.modules.general")
.
Examples
# general data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
require(nestcolor)
mtcars <- mtcars
for (v in c("cyl", "vs", "am", "gear")) {
mtcars[[v]] <- as.factor(mtcars[[v]])
}
})
datanames(data) <- "mtcars"
app <- init(
data = data,
modules = modules(
tm_g_response(
label = "Response Plots",
response = data_extract_spec(
dataname = "mtcars",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["mtcars"]], c("cyl", "gear")),
selected = "cyl",
multiple = FALSE,
fixed = FALSE
)
),
x = data_extract_spec(
dataname = "mtcars",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["mtcars"]], c("vs", "am")),
selected = "vs",
multiple = FALSE,
fixed = FALSE
)
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Response Module")
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- rADSL
})
datanames(data) <- c("ADSL")
join_keys(data) <- default_cdisc_join_keys[datanames(data)]
app <- init(
data = data,
modules = modules(
tm_g_response(
label = "Response Plots",
response = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")),
selected = "BMRKR2",
multiple = FALSE,
fixed = FALSE
)
),
x = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")),
selected = "RACE",
multiple = FALSE,
fixed = FALSE
)
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Response Module")
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}