Create a simple scatterplot
tm_g_scatterplot.Rd
Create a plot with the ggplot2[geom_point]
function
Usage
tm_g_scatterplot(
label = "Scatterplot",
x,
y,
color_by = NULL,
size_by = NULL,
row_facet = NULL,
col_facet = NULL,
plot_height = c(600, 200, 2000),
plot_width = NULL,
alpha = c(1, 0, 1),
shape = shape_names,
size = c(5, 1, 15),
max_deg = 5L,
rotate_xaxis_labels = FALSE,
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void",
"test"),
pre_output = NULL,
post_output = NULL,
table_dec = 4,
ggplot2_args = teal.widgets::ggplot2_args()
)
Arguments
- label
(
character
) Label shown in the navigation item for the module.- x
(
data_extract_spec
orlist
of multipledata_extract_spec
) Variable names selected to plot along the x-axis by default.- y
(
data_extract_spec
orlist
of multipledata_extract_spec
) Variable names selected to plot along the y-axis by default.- color_by
optional (
data_extract_spec
orlist
of multipledata_extract_spec
) Defines the color encoding. IfNULL
then no color encoding option will be displayed.- size_by
optional (
data_extract_spec
orlist
of multipledata_extract_spec
) Defines the point size encoding. IfNULL
then no size encoding option will be displayed.- row_facet
optional, (
data_extract_spec
orlist
of multipledata_extract_spec
) Which data columns to use for faceting rows.- col_facet
optional, (
data_extract_spec
orlist
of multipledata_extract_spec
) Which data to use for faceting columns.- plot_height
optional, (
numeric
) A vector of length three withc(value, min and max)
for a slider encoding the plot height.- plot_width
optional, (
numeric
) A vector of length three withc(value, min and max)
for a slider encoding the plot width.- alpha
optional, (
numeric
) If scalar then the plot points will have a fixed opacity. If a slider should be presented to adjust the plot point opacity dynamically then it can be a vector of length three withc(value, min, max)
.- shape
optional, (
character
) A character vector with the English names of the shape, e.g.c("triangle", "square", "circle")
. It defaults toshape_names
. This is a complete list fromvignette("ggplot2-specs", package="ggplot2")
.- size
optional, (
numeric
) If scalar then the plot point sizes will have a fixed size If a slider should be presented to adjust the plot point sizes dynamically then it can be a vector of length three withc(value, min, max)
.- max_deg
optional, (
integer
) The maximum degree for the polynomial trend line. Must not be less than 1.- rotate_xaxis_labels
optional, (
logical
) Whether to rotate plot X axis labels. Does not rotate by default (FALSE
).- ggtheme
optional, (
character
)ggplot2
theme to be used by default. One ofc("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void", "test")
. Each theme can be chosen by the user during the session. Defaults to"gray"
.- 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.- table_dec
optional, (
integer
) Number of decimal places used to round numeric values in the table.- ggplot2_args
-
(
ggplot2_args
) object created byteal.widgets::ggplot2_args()
with settings for the module plot. The argument is merged with options variableteal.ggplot2_args
and default module setup.For more details see the vignette:
vignette("custom-ggplot2-arguments", package = "teal.widgets")
Note
For more examples, please see the vignette "Using scatterplot" via
vignette("using-scatterplot", package = "teal.modules.general")
.
Examples
# Scatterplot of variables from ADSL dataset
library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl
app <- init(
data = cdisc_data(
cdisc_dataset("ADSL", ADSL, code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"),
check = TRUE
),
modules = modules(
tm_g_scatterplot(
label = "Scatterplot Choices",
x = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")),
selected = "AGE",
multiple = FALSE,
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")),
selected = "BMRKR1",
multiple = FALSE,
fixed = FALSE
)
),
color_by = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
size_by = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")),
selected = "AGE",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
ggplot2_args = teal.widgets::ggplot2_args(labs = list(subtitle = "Plot generated by Scatterplot Module"))
)
)
)
#> [INFO] 2022-06-14 17:42:38.0558 pid:1110 token:[] teal.modules.general Initializing tm_g_scatterplot
if (FALSE) {
shinyApp(app$ui, app$server)
}