epi_plot_box: Boxplot wrapper function using ggplot2

View source: R/epi_plot_box.R

epi_plot_boxR Documentation

Boxplot wrapper function using ggplot2

Description

epi_plot_box() wraps ggplot2 boxplot for one or two variables with a number of set preferences, see below.

Usage

epi_plot_box(df = NULL, var_y = NULL, var_x = "",
  outlier_alpha = 0.7, fill = "grey80", colour = "grey20",
  stat_geom = "errorbar", stat_width = 0.5, jitter_shape = 16,
  jitter_position = 0.2, jitter_alpha = 0.5, sum_fun.y = mean,
  sum_geom = "point", sum_shape = 23, sum_size = 4, ...)

Arguments

df

data.frame with x var to plot

var_y

Variable to plot on y-axis, pass as a string.

var_x

Variable to plot on x-axis, pass as a string.

outlier_alpha

Outlier transparency. Default is 0.7.

fill

Interior colour used to fill. If only passing var_y it defaults to 'grey80'. If passing both var_y and var_x, it uses var_x.

colour

Aesthetics for ggplot2. Default is 'grey20' if only var_y.

stat_geom

ggplot2::stat_boxplot parameter used for 2 variable boxplot only. Default is 'errorbar'.

stat_width

ggplot2::stat_boxplot parameter used for 2 variable boxplot only. Default is 0.5.

jitter_shape

ggplot2::geom_jitter parameter used for 2 variable boxplot only. Default is 16.

jitter_position

ggplot2::geom_jitter parameter used for 2 variable boxplot only. Default is 0.2.

jitter_alpha

ggplot2::geom_jitter parameter used for 2 variable boxplot only. Default is 0.5.

sum_fun.y

ggplot2::stat_summary parameter used for 2 variable boxplot only. Default is mean.

sum_geom

ggplot2::stat_summary parameter used for 2 variable boxplot only. Default is "point".

sum_shape

ggplot2::stat_summary parameter used for 2 variable boxplot only. Default is 23.

sum_size

ggplot2::stat_summary parameter used for 2 variable boxplot only. Default is 4.

...

passes any further arguments to ggplot2::geom_boxplot() for both one and two column plots.

Value

Prints a ggplot2 boxplot

Note

For other options, save as object and build on the layers. var_x and var_y are passed to ggplot2::aes_string. For colour and fill see ggplot2::fill for further information.

Author(s)

Antonio Berlanga-Taylor <https://github.com/AntonioJBT/episcout>

See Also

epi_plot_list, epi_plots_to_grid, epi_plot_hist, ggplot, geom_boxplot.

Examples


## Not run: 
Boxplot of one variable:
library(ggplot2)
library(ggthemes)
set.seed(12345)
n <- 20
df <- data.frame(var_id = rep(1:(n / 2), each = 2),
                 var_to_rep = rep(c("Pre", "Post"), n / 2),
                 x = rnorm(n),
                 y = rbinom(n, 1, 0.50),
                 z = rpois(n, 2)
                 )
df
df$x # continuous variable
epi_plot_box(df, var_y = 'x')
# Add notch:
epi_plot_box(df, var_y = 'x', notch = TRUE)

# Boxplot for x and y variables:
df$x # continuous variable
df$var_to_rep # factor
epi_plot_box(df, var_x = 'var_to_rep', var_y = 'x')
# Change colours, remove legend, etc.:
my_boxplot <- epi_plot_box(df, var_x = 'var_to_rep', var_y = 'x')
my_boxplot +
  # scale_fill_grey() +
scale_fill_brewer(palette = "Blues") +
  # scale_fill_brewer(palette = "Dark2") +
  theme(legend.position = "none") # Remove legend
# dev.off()

## End(Not run)


AntonioJBT/episcout documentation built on May 8, 2024, 11:02 p.m.