Create a new tidyplot
Usage
tidyplot(
data,
...,
width = NULL,
height = NULL,
unit = NULL,
dodge_width = NULL,
my_style = NULL
)
Arguments
- data
A tidy
data.frame
to use for plotting.- ...
Mappings for the
x
axis,y
axis andcolor
, see examples. Additional argument are passed toggplot2::aes()
.- width
Width of the plot area. Defaults to the value
tidyplots.width
in the globaloptions()
. If neither the parameterwidth
nor the global optiontidyplots.width
is provided, it falls back to50
.- height
Height of the plot area. Defaults to the value
tidyplots.height
in the globaloptions()
. If neither the parameterheight
nor the global optiontidyplots.height
is provided, it falls back to50
.- unit
Unit of the plot area width and height. Defaults to the value
tidyplots.unit
in the globaloptions()
. If neither the parameterunit
nor the global optiontidyplots.unit
is provided, it falls back to"mm"
.- dodge_width
For adjusting the distance between grouped objects. Defaults to the value
tidyplots.dodge_width
in the globaloptions()
. If neither the parameterdodge_width
nor the global optiontidyplots.dodge_width
is provided, it falls back to0.8
for plots with at least one discrete axis and to0
for plots with two continuous axes.- my_style
Styling function to apply to the plot. Defaults to to the value
tidyplots.my_style
in the globaloptions()
. If neither the parametermy_style
nor the global optiontidyplots.my_style
is provided, no styling function is applied
Examples
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_data_points_beeswarm()
study |>
tidyplot(x = group, y = score, color = dose) |>
add_mean_bar()
# Change plot area size
study |>
tidyplot(x = treatment, y = score, color = treatment,
width = 25, height = 25) |>
add_data_points_beeswarm()
# Change dodge_width
study |>
tidyplot(x = group, y = score, color = dose, dodge_width = 0.3) |>
add_mean_bar()
# Use global options
## Define custom style
my_style <- function(x) x |>
adjust_colors(colors_discrete_candy) |>
adjust_font(family = "mono")
## Set global options
options(
tidyplots.width = 3,
tidyplots.height = 4,
tidyplots.unit = "cm",
tidyplots.dodge_width = 1,
tidyplots.my_style = my_style
)
## Plot
study |>
tidyplot(x = group, y = score, color = dose) |>
add_mean_bar()
## Reset global options
options(
tidyplots.width = NULL,
tidyplots.height = NULL,
tidyplots.unit = NULL,
tidyplots.dodge_width = NULL,
tidyplots.my_style = NULL
)
## Same plot
study |>
tidyplot(x = group, y = score, color = dose) |>
add_mean_bar()