diff --git a/DESCRIPTION b/DESCRIPTION
index 23e62616..32e1f290 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -21,6 +21,7 @@ Imports:
glue,
Hmisc,
htmltools,
+ lifecycle,
patchwork,
purrr,
rlang,
diff --git a/NAMESPACE b/NAMESPACE
index 8133bcfc..7d4d1ef3 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -139,6 +139,7 @@ importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.off)
importFrom(grDevices,pdf)
importFrom(grDevices,rgb)
+importFrom(lifecycle,deprecated)
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(stats,density)
diff --git a/R/adjust.R b/R/adjust.R
index c2a7cf5c..3f17fd59 100644
--- a/R/adjust.R
+++ b/R/adjust.R
@@ -122,8 +122,52 @@ ff_adjust_axis <- function(axis) {
#' @param rotate_labels Whether to rotate axis labels. If `TRUE` is set to 45 degrees. You can also provide custom degree values, for example, `rotate_labels = 90`. Defaults to `FALSE`.
#' @param cut_short_scale Whether to shorten axis labels using `K` for thousand, `M` for million, and so on. Defaults to `FALSE`.
#' @param padding Extra space between the data points and the axes. Defaults to `c(NA, NA)`, which does not change the padding.
+#' @param ... Arguments passed on to ggplot2 `scale` function.
#' @inherit common_arguments
#' @inheritParams ggplot2::scale_x_continuous
+#'
+#' @details
+#' * The `title` argument of `adjust_x_axis()` and `adjust_y_axis()` supports [plotmath expressions](https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath) to include special characters.
+#' See examples and [Advanced plotting](https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters).
+#'
+#' @examples
+#' # New titles
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(title = "My new x axis title") %>%
+#' adjust_y_axis(title = "My new y axis title")
+#' # New titles with plotmath expressions
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(title = "$H[2]*O$") %>%
+#' adjust_y_axis(title = "$E==m*c^{2}$")
+#' # Axes limits
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(limits = c(-1000, 4000)) %>%
+#' adjust_y_axis(limits = c(-200, 600))
+#' # Rotate labels
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(rotate_labels = 90) %>%
+#' adjust_y_axis(rotate_labels = 90)
+#' # Increase plot area padding
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(padding = c(0.2, 0.2)) %>%
+#' adjust_y_axis(padding = c(0.2, 0.2))
+#' # Scale transformation
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_x_axis(transform = "log10") %>%
+#' adjust_y_axis(transform = "log2")
+#'
#' @export
adjust_x_axis <- ff_adjust_axis("x")
#' @rdname adjust_x_axis
@@ -133,6 +177,30 @@ adjust_y_axis <- ff_adjust_axis("y")
#' Adjust plot area size
#' @inherit common_arguments
+#'
+#' @examples
+#' # Resize to 20 x 20 mm
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm(shape = 1) %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_plot_area_size(width = 20, height = 20)
+#' # Resize to 4 x 4 cm
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm(shape = 1) %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_plot_area_size(width = 4, height = 4, unit = "cm")
+#' # Remove absolute dimensions and take all available space. This is the ggplot2 default.
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm(shape = 1) %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_plot_area_size(width = NA, height = NA)
+#'
#' @export
adjust_plot_area_size <- function(plot, width = 50, height = 50, unit = "mm") {
check_tidyplot(plot)
@@ -146,6 +214,30 @@ adjust_plot_area_size <- function(plot, width = 50, height = 50, unit = "mm") {
#' Adjust font
#' @inherit common_arguments
#' @inheritParams ggplot2::element_text
+#'
+#' @examples
+#' # Increase font size
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_font(fontsize = 16)
+#' # Change font family
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_font(family = "mono")
+#' # Change font face
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_font(face = "bold")
+#'
#' @export
adjust_font <- function(plot, fontsize = 7, family = NULL, face = NULL, color = "black") {
check_tidyplot(plot)
@@ -166,9 +258,56 @@ adjust_font <- function(plot, fontsize = 7, family = NULL, face = NULL, color =
#' Adjust legend
#' @param title Legend title.
-#' @param position The position of legends. Can be one of `"none"`, `"left"`, `"right"`,
-#' `"bottom"`, `"top"`, or a two-element numeric vector.
+#' @param position The position of the legend. Can be one of
+#' `c("right", "left", "bottom", "top", "none")`. Defaults to `"right"`.
#' @inherit common_arguments
+#'
+#' @details
+#' * The `title` argument of `adjust_legend()` supports [plotmath expressions](https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath) to include special characters.
+#' See examples and [Advanced plotting](https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters).
+#'
+#' @examples
+#' # New title
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(title = "My new legend title")
+#' # New title with plotmath expression
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(title = "$E==m*c^{2}$")
+#' # Alternative legend positions
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(position = "left")
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(position = "top")
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(position = "bottom")
+#' # `position = "none"` hides the legend
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points_beeswarm() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_legend(position = "none")
+#'
#' @export
adjust_legend <- function(plot, title = ggplot2::waiver(), position = "right") {
check_tidyplot(plot)
@@ -187,6 +326,35 @@ adjust_legend <- function(plot, title = ggplot2::waiver(), position = "right") {
#' @param left Extra space between the data points and the left. Defaults to `NA`, which does not change the padding.
#' @param all Extra space around the data pointst. Overwrites `top`, `right`, `bottom`, `left` if set. Defaults to `NA`, which does not change the padding.
#' @inherit common_arguments
+#'
+#' @examples
+#' # Original plot
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding()
+#' # Increase plot area padding
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding(all = 0.2)
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding(top = 0.8)
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding(bottom = 0.8)
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding(right = 0.8)
+#' animals %>%
+#' tidyplot(x = weight, y = size, color = number_of_legs) %>%
+#' add_data_points() %>%
+#' adjust_plot_area_padding(left = 0.8)
+#'
#' @export
adjust_plot_area_padding <- function(plot, top = NA, right = NA, bottom = NA, left = NA, all = NA, force_continuous = FALSE, ...) {
check_tidyplot(plot)
@@ -207,6 +375,36 @@ adjust_plot_area_padding <- function(plot, top = NA, right = NA, bottom = NA, le
#' @param caption Plot caption text.
#' @param ... Arguments passed on to `ggplot2::labs()`.
#' @inherit common_arguments
+#'
+#' @details
+#' * `adjust_description()` supports [plotmath expressions](https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath) to include special characters.
+#' See examples and [Advanced plotting](https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters).
+#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_description(
+#' title = "This is my fantastic plot title",
+#' x_axis_title = "Treatment group",
+#' y_axis_title = "Disease score",
+#' legend_title = "Legend title",
+#' caption = "Here goes the caption")
+#' # Plotmath expressions
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_description(
+#' title = "$H[2]*O$",
+#' x_axis_title = "$H[2]*O$",
+#' y_axis_title = "$H[2]*O$",
+#' legend_title = "$H[2]*O$",
+#' caption = "$H[2]*O$")
+#'
#' @export
adjust_description <- function(plot, title = ggplot2::waiver(), x_axis_title = ggplot2::waiver(),
y_axis_title = ggplot2::waiver(), legend_title = ggplot2::waiver(),
diff --git a/R/colors.R b/R/colors.R
index a9e25c4c..29ccd386 100644
--- a/R/colors.R
+++ b/R/colors.R
@@ -1,8 +1,43 @@
#' Adjust colors
#' @param new_colors A character vector of new hex colors to use. Can be a named character vector of hex colors to assign certain data labels to specific colors.
-#' @param ... Arguments passed on to the `scale` function.
+#' @param ... Arguments passed on to the ggplot2 `scale` function.
#' @inherit common_arguments
#' @inheritParams ggplot2::scale_x_continuous
+#'
+#' @seealso [colors_discrete_metro()], [colors_continuous_viridis()], [colors_diverging_blue2brown()], and [new_color_scheme()]
+#'
+#' @examples
+#' # Provide hex colors
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_colors(new_colors = c("#644296","#F08533","#3B78B0", "#D1352C"))
+#' # Provide discrete color scheme
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_colors(new_colors = colors_discrete_seaside)
+#' # Provide name vector
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' adjust_colors(new_colors = c(
+#' "A" = "pink",
+#' "B" = "purple",
+#' "C" = "grey",
+#' "D" = "blue"))
+#' # Provide continuous color scheme
+#' climate %>%
+#' tidyplot(x = month, y = year, color = max_temperature) %>%
+#' add_heatmap() %>%
+#' adjust_colors(new_colors = colors_continuous_turbo)
+#'
#' @export
adjust_colors <- function(plot, new_colors = NULL,
saturation = 1,
diff --git a/R/data.R b/R/data.R
index 9dde2215..bdc42102 100644
--- a/R/data.R
+++ b/R/data.R
@@ -10,7 +10,7 @@
"gene_expression"
#' Time course data
-#' @format A data frame with.
+#' @format A data frame.
#' @source
#' tidyplots package
#' @examples
diff --git a/R/feature_requests.R b/R/feature_requests.R
deleted file mode 100644
index a14fd4ca..00000000
--- a/R/feature_requests.R
+++ /dev/null
@@ -1,36 +0,0 @@
-
-# it would be nice to have a Graphpad Prism-like x-jitter
-# however, availbale sulutions are still not quite there
-# https://github.com/eclarke/ggbeeswarm
-
-# also: Does ggbeeswarm work with ggrepel?
-
-# library(tidyverse)
-# library(tidyplots)
-#
-# p <-
-# animals %>%
-# tidyplot(family, size, color = family) %>%
-# add_mean_bar(alpha = 0.3) %>%
-# add_sem_bar() %>%
-# adjust_data_labels(family, sort_by = size)
-#
-# # default random jitter
-# p + ggplot2::geom_point(size = 1)
-# p + ggplot2::geom_jitter(width = 0.2, size = 1)
-#
-# # preserves y values but distribution looks skewed
-# p + ggplot2::geom_point(size = 1)
-# p + ggbeeswarm::geom_beeswarm(cex = 3, corral = "wrap", corral.width = 0.5, size = 1)
-#
-# # points are centered, but y values are altered
-# p + ggplot2::geom_point(size = 1)
-# p + ggbeeswarm::geom_beeswarm(cex = 3.5, method = "center", corral = "wrap", corral.width = 0.5, size = 1)
-#
-# p + ggplot2::geom_point(size = 1)
-# p + ggbeeswarm::geom_quasirandom(size = 1, method = "quasirandom", width = 0.2)
-#
-# p + ggplot2::geom_point(size = 1)
-# p + ggbeeswarm::geom_quasirandom(size = 1, method = "tukey", width = 0.2)
-#
-#
diff --git a/R/helpers.R b/R/helpers.R
index d515ee18..7088f511 100644
--- a/R/helpers.R
+++ b/R/helpers.R
@@ -14,6 +14,15 @@ is_waiver <- function(x) inherits(x, "waiver")
#'
#' @param gg A ggplot.
#' @inherit common_arguments
+#'
+#' @examples
+#' gg <-
+#' study %>%
+#' ggplot2::ggplot(ggplot2::aes(x = treatment, y = score, color = treatment)) +
+#' ggplot2::geom_point()
+#' gg
+#' gg %>% as_tidyplot()
+#'
#' @export
as_tidyplot <- function(gg, width = 50, height = 50, dodge_width = 0.8) {
mapping <- gg$mapping
@@ -62,6 +71,34 @@ as_tidyplot <- function(gg, width = 50, height = 50, dodge_width = 0.8) {
#' Flip x and y axis
#' @param ... Arguments passed on to `ggplot2::coord_flip()`.
#' @inherit common_arguments
+#' @description
+#' `r lifecycle::badge("superseded")`
+#'
+#' This function is superseded because in many cases, `flip_plot()` can easily
+#' be replaced by swapping the `x` and `y` axis. Some plot components additionally
+#' require to set the `orientation` argument to `"y"`.
+#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' flip_plot()
+#' energy %>%
+#' tidyplot(x = year, y = power, color = energy_type) %>%
+#' add_barstack_absolute() %>%
+#' flip_plot()
+#' # Better solutions without `flip_plot()`
+#' study %>%
+#' tidyplot(x = score, y = treatment, color = treatment) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar()
+#' energy %>%
+#' tidyplot(x = power, y = year, color = energy_type) %>%
+#' add_barstack_absolute(orientation = "y")
+#'
#' @export
flip_plot <- function(plot, ...) {
check_tidyplot(plot)
@@ -92,6 +129,45 @@ filter_rows <- function(..., .by = NULL){
#' they will only be included if there are insufficient non-missing values to
#' reach `n`.
#' @inheritParams dplyr::slice_max
+#'
+#' @examples
+#' # Highlight all animals
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = all_rows(),
+#' color = "red", shape = 1, size = 3)
+#' # Highlight 3 animals with the highest weight
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = max_rows(weight, n = 3),
+#' color = "red", shape = 1, size = 3)
+#' # Highlight 3 animals with the lowest weight
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = min_rows(weight, n = 3),
+#' color = "red", shape = 1, size = 3)
+#' # Highlight the 3 first animals in the dataset
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = first_rows(n = 3),
+#' color = "red", shape = 1, size = 3)
+#' # Highlight the 3 last animals in the dataset
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = last_rows(n = 3),
+#' color = "red", shape = 1, size = 3)
+#' # Highlight 3 random animals
+#' animals %>%
+#' tidyplot(x = weight, y = size) %>%
+#' add_data_points() %>%
+#' add_data_points(data = sample_rows(n = 3),
+#' color = "red", shape = 1, size = 3)
+#'
#' @export
max_rows <- function(order_by, n, by = NULL, with_ties = TRUE, na_rm = FALSE){
. %>% dplyr::slice_max(order_by = {{order_by}}, n = n, by = {{by}}, with_ties = with_ties, na_rm = na_rm)
@@ -127,11 +203,19 @@ sample_rows <- function(n, by = NULL){
#' @param ... Arguments passed on to `scales::number()`.
#' @inheritParams scales::number
#' @inheritDotParams scales::number scale style_positive style_negative
+#'
+#' @examples
+#' format_number(232342.3443)
+#' format_number(232342.3443, accuracy = 0.01)
+#' format_number(232342.3443, accuracy = 1, big.mark = "")
+#' format_p_value(0.03445553)
+#' format_p_value(0.0003445553)
+#' format_p_value(0.00003445553)
+#'
#' @export
format_number <- function(x, accuracy = 0.1, big.mark =",", scale_cut = NULL, ...) {
scales::number(x = x, accuracy = accuracy, big.mark = big.mark, scale_cut = scale_cut, ...)
}
-
#' @rdname format_number
#' @export
format_p_value <- function(x, accuracy = 0.0001) {
diff --git a/R/labels.R b/R/labels.R
index b8a2be50..112889d6 100644
--- a/R/labels.R
+++ b/R/labels.R
@@ -34,6 +34,37 @@ ff_rename_axis_labels <- function(axis) {
#'
#' @param new_names Named character vector in the format c("old1" = "new1", "old2" = "new2").
#' @inherit common_arguments
+#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' rename_x_axis_labels(new_names = c(
+#' "A" = "This",
+#' "B" = "is",
+#' "C" = "totally",
+#' "D" = "new"))
+#' study %>%
+#' tidyplot(x = score, y = treatment, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' rename_y_axis_labels(new_names = c(
+#' "A" = "This",
+#' "B" = "is",
+#' "C" = "totally",
+#' "D" = "new"))
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' rename_color_labels(new_names = c(
+#' "placebo" = "The first",
+#' "treatment" = "The second"))
+#'
#' @export
rename_x_axis_labels <- ff_rename_axis_labels(axis = "x")
#' @rdname rename_x_axis_labels
@@ -62,6 +93,27 @@ ff_reorder_axis_labels <- function(axis) {
#'
#' @inherit common_arguments
#' @param ... Arguments passed on to `forcats::fct_relevel()`.
+#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reorder_x_axis_labels("D", "B")
+#' study %>%
+#' tidyplot(x = score, y = treatment, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reorder_y_axis_labels("D", "B")
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reorder_color_labels("treatment")
+#'
#' @export
reorder_x_axis_labels <- ff_reorder_axis_labels(axis = "x")
#' @rdname reorder_x_axis_labels
@@ -88,6 +140,26 @@ ff_sort_axis_labels <- function(axis) {
}
#' Sort axis or color labels
#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' sort_x_axis_labels(score)
+#' study %>%
+#' tidyplot(x = score, y = treatment, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' sort_y_axis_labels(-score)
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' sort_color_labels(-score)
+#'
#' @inherit common_arguments
#' @param ... Arguments passed on to `forcats::fct_reorder()`.
#' @export
@@ -115,6 +187,26 @@ ff_reverse_axis_labels <- function(axis) {
}
#' Reverse axis or color labels
#'
+#' @examples
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reverse_x_axis_labels()
+#' study %>%
+#' tidyplot(x = score, y = treatment, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reverse_y_axis_labels()
+#' study %>%
+#' tidyplot(x = treatment, y = score, color = group) %>%
+#' add_data_points() %>%
+#' add_mean_bar(alpha = 0.3) %>%
+#' add_sem_bar() %>%
+#' reverse_color_labels()
+#'
#' @inherit common_arguments
#' @export
reverse_x_axis_labels <- ff_reverse_axis_labels(axis = "x")
diff --git a/R/plot.R b/R/plot.R
index 6cc19bff..0cf9221c 100644
--- a/R/plot.R
+++ b/R/plot.R
@@ -2,6 +2,24 @@
#'
#' @param ... Mappings for the `x` axis, `y` axis and `color`, see examples. Additional argument are passed to `ggplot2::aes()`.
#' @inherit common_arguments
+#'
+#' @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 = 35, height = 35) %>%
+#' add_data_points_beeswarm()
+#' # Change dodge_width
+#' study %>%
+#' tidyplot(x = group, y = score, color = dose, dodge_width = 0.3) %>%
+#' add_mean_bar()
+#'
#' @export
tidyplot <- function(data, ..., width = 50, height = 50, dodge_width = 0.8) {
mapping <- ggplot2::aes(...)
@@ -53,18 +71,18 @@ tidyplot <- function(data, ..., width = 50, height = 50, dodge_width = 0.8) {
#' @param unit Unit of length. Defaults to `"mm"`.
#' @inheritParams patchwork::wrap_plots
#' @inherit common_arguments
+#'
+#' @examples
+#' energy %>%
+#' dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) %>%
+#' tidyplot(y = power, color = energy_source) %>%
+#' add_donut() %>%
+#' split_plot(by = year)
+#'
#' @export
-split_plot <- function(plot,
- by,
- ncol = NULL,
- nrow = NULL,
- byrow = NULL,
- widths = 30,
- heights = 25,
- guides = "collect",
- tag_level = NULL,
- design = NULL,
- unit = "mm") {
+split_plot <- function(plot, by, ncol = NULL, nrow = NULL, byrow = NULL,
+ widths = 30, heights = 25, guides = "collect",
+ tag_level = NULL, design = NULL, unit = "mm") {
check_tidyplot(plot)
if(missing(by))
cli::cli_abort("Argument {.arg by} missing without default.")
@@ -78,15 +96,35 @@ split_plot <- function(plot,
plot$data %>%
tidyr::nest(data = -{{by}}) %>%
dplyr::arrange({{by}})
+
plots <-
purrr::map2(df$data, df %>% dplyr::pull({{by}}),
function(data, facet_title) {
plot %+% data + ggplot2::ggtitle(facet_title)
})
- # cli::cli_alert_success("split_plot: {.pkg widths} = {widths} {unit}, {.pkg heights} = {heights} {unit}")
+
if (!is.na(widths)) widths <- ggplot2::unit(widths, unit)
if (!is.na(heights)) heights <- ggplot2::unit(heights, unit)
- out <- multipage_plots(plots, ncol = ncol, nrow = nrow, widths = widths, heights = heights, unit = unit, guides = guides, byrow = byrow, tag_level = tag_level, design = design)
+
+ # if (!ggplot2::is.ggplot(plots) && !all(purrr::map_lgl(plots, ggplot2::is.ggplot)))
+ # cli::cli_abort("{.arg plots} must be a single plot or a list of plots.")
+ # if (ggplot2::is.ggplot(plots)) plots <- list(plots)
+
+ if (is.numeric(ncol) && is.numeric(nrow)) {
+ plots_per_page <- nrow * ncol
+ } else {
+ plots_per_page <- length(plots)
+ }
+
+ pages <-
+ split(plots, ceiling(seq_along(plots)/plots_per_page)) %>%
+ purrr::map(., ~patchwork::wrap_plots(.x, ncol = ncol, nrow = nrow, widths = widths,
+ heights = heights, guides = guides, byrow = byrow,
+ tag_level = tag_level, design = design))
+
+ cli::cli_alert_success("split_plot: split into {.pkg {length(plots)} plot{?s}} across {.pkg {ceiling(length(plots)/plots_per_page)} page{?s}}")
+
+ out <- unname(pages)
if (length(out) == 1) out <- out[[1]]
out
}
@@ -131,7 +169,6 @@ save_plot <- function(plot = ggplot2::last_plot(), filename,
if (!ggplot2::is.ggplot(plot) && !all(purrr::map_lgl(plot, ggplot2::is.ggplot)))
cli::cli_abort("{.arg plot} must be a single plot or a list of plots.")
- print(plot)
input <- plot
if (ggplot2::is.ggplot(plot)) plot <- list(plot)
units <- match.arg(units)
@@ -141,24 +178,22 @@ save_plot <- function(plot = ggplot2::last_plot(), filename,
else
dimensions <- list(width = NA, height = NA)
- width_defined_by <- dplyr::case_when(is.na(width) && is.na(dimensions[["width"]]) ~ "was not defined - system default used",
- !is.na(width) ~ "was provided as argument 'width'",
- TRUE ~ "was inferred from plot dimensions")
- height_defined_by <- dplyr::case_when(is.na(height) && is.na(dimensions[["height"]]) ~ "was not defined - system default used",
- !is.na(height) ~ "was provided as argument 'height'",
- TRUE ~ "was inferred from plot dimensions")
+ # width_defined_by <- dplyr::case_when(is.na(width) && is.na(dimensions[["width"]]) ~ "was not defined - system default used",
+ # !is.na(width) ~ "was provided as argument 'width'",
+ # TRUE ~ "was inferred from plot dimensions")
+ # height_defined_by <- dplyr::case_when(is.na(height) && is.na(dimensions[["height"]]) ~ "was not defined - system default used",
+ # !is.na(height) ~ "was provided as argument 'height'",
+ # TRUE ~ "was inferred from plot dimensions")
+ # cli::cli_alert_success("save_plot: {.pkg page width} {width_defined_by}")
+ # cli::cli_alert_success("save_plot: {.pkg page height} {height_defined_by}")
if (is.na(width)) width <- dimensions[["width"]] * 1.1
if (is.na(height)) height <- dimensions[["height"]] * 1.1
- # cli::cli_alert_success("save_plot: {.pkg page width} {width_defined_by}")
- # cli::cli_alert_success("save_plot: {.pkg page height} {height_defined_by}")
- # cli::cli_alert_success("save_plot: saving {.pkg {length(plot)} page{?s}} with {.pkg {round(width)} x {round(height)}} mm to {.file {filename}}")
-
if (length(plot) == 1) {
# single plot
ggplot2::ggsave(plot = plot[[1]], filename = filename, width = width,
- height = height, units = units, bg = bg,...)
+ height = height, units = units, bg = bg, ...)
cli::cli_alert_success("save_plot: saved to {.file {filename}}")
} else{
# multiple plots
@@ -187,32 +222,6 @@ save_plot <- function(plot = ggplot2::last_plot(), filename,
cli::cli_alert_success("save_plot: saved multiple plots to {.file {filenames}}")
}
}
+ print(input)
invisible(input)
}
-
-# not exported
-multipage_plots <- function(plot,
- ncol = NULL,
- nrow = NULL,
- byrow = NULL,
- widths = 30,
- heights = 25,
- guides = "collect",
- tag_level = NULL,
- design = NULL,
- unit ="mm") {
- if (!ggplot2::is.ggplot(plot) && !all(purrr::map_lgl(plot, ggplot2::is.ggplot)))
- cli::cli_abort("{.arg plot} must be a single plot or a list of plots.")
- if (ggplot2::is.ggplot(plot)) plot <- list(plot)
-
- if (is.numeric(ncol) & is.numeric(nrow)) {
- plots_per_page <- nrow * ncol
- } else {
- plots_per_page <- length(plot)
- }
- cli::cli_alert_success("split_plot: split into {.pkg {length(plot)} plots} across {.pkg {ceiling(length(plot)/plots_per_page)} pages} on a {.pkg {ncol} x {nrow}} grid")
- pages <-
- split(plot, ceiling(seq_along(plot)/plots_per_page)) %>%
- purrr::map(., ~patchwork::wrap_plots(.x, ncol = ncol, nrow = nrow, widths = widths, heights = heights, guides = guides, byrow = byrow, tag_level = tag_level, design = design))
- unname(pages)
-}
diff --git a/R/tidyplots-package.R b/R/tidyplots-package.R
new file mode 100644
index 00000000..425b3c1c
--- /dev/null
+++ b/R/tidyplots-package.R
@@ -0,0 +1,7 @@
+#' @keywords internal
+"_PACKAGE"
+
+## usethis namespace: start
+#' @importFrom lifecycle deprecated
+## usethis namespace: end
+NULL
diff --git a/README.Rmd b/README.Rmd
index b281e53b..164dbaf1 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -52,14 +52,12 @@ study %>%
add_mean_bar(alpha = 0.3) %>%
add_sem_bar() %>%
add_data_points_beeswarm()
-
```
```{r}
energy %>%
tidyplot(x = year, y = power, color = energy_source) %>%
add_barstack_absolute()
-
```
```{r}
@@ -68,21 +66,18 @@ energy %>%
tidyplot(y = power, color = energy_source) %>%
add_donut() %>%
split_plot(by = year)
-
```
```{r}
energy_week %>%
tidyplot(x = date, y = power, color = energy_source) %>%
add_areastack_absolute()
-
```
```{r}
energy_week %>%
tidyplot(x = date, y = power, color = energy_source) %>%
add_areastack_relative()
-
```
```{r}
@@ -91,7 +86,6 @@ study %>%
add_mean_bar(alpha = 0.3) %>%
add_mean_dash() %>%
add_mean_value()
-
```
```{r}
@@ -100,7 +94,6 @@ time_course %>%
add_mean_line() %>%
add_mean_dot() %>%
add_sem_ribbon()
-
```
```{r, fig.height=3}
@@ -108,7 +101,6 @@ study %>%
tidyplot(x = treatment, y = score, color = treatment) %>%
add_boxplot() %>%
add_stats_pvalue(ref.group = 1)
-
```
```{r, fig.height=3.2}
@@ -121,7 +113,6 @@ gene_expression %>%
add_stats_asterisks(hide_info = TRUE) %>%
remove_x_axis_title() %>%
split_plot(by = external_gene_name)
-
```
```{r}
@@ -133,7 +124,6 @@ study %>%
view_plot(title = "Default color scheme: metro") %>%
adjust_colors(colors_discrete_seaside) %>%
view_plot(title = "Alternative color scheme: seaside")
-
```
## Acknowledgements
diff --git a/man/adjust_colors.Rd b/man/adjust_colors.Rd
index b0b8ce6a..0dc603c5 100644
--- a/man/adjust_colors.Rd
+++ b/man/adjust_colors.Rd
@@ -31,7 +31,7 @@ as output. Also accepts rlang \link[rlang:as_function]{lambda} function
notation.
}}
-\item{...}{Arguments passed on to the \code{scale} function.}
+\item{...}{Arguments passed on to the ggplot2 \code{scale} function.}
}
\value{
A \code{tidyplot} object
@@ -39,3 +39,39 @@ A \code{tidyplot} object
\description{
Adjust colors
}
+\examples{
+# Provide hex colors
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_colors(new_colors = c("#644296","#F08533","#3B78B0", "#D1352C"))
+# Provide discrete color scheme
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_colors(new_colors = colors_discrete_seaside)
+# Provide name vector
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_colors(new_colors = c(
+ "A" = "pink",
+ "B" = "purple",
+ "C" = "grey",
+ "D" = "blue"))
+# Provide continuous color scheme
+climate \%>\%
+ tidyplot(x = month, y = year, color = max_temperature) \%>\%
+ add_heatmap() \%>\%
+ adjust_colors(new_colors = colors_continuous_turbo)
+
+}
+\seealso{
+\code{\link[=colors_discrete_metro]{colors_discrete_metro()}}, \code{\link[=colors_continuous_viridis]{colors_continuous_viridis()}}, \code{\link[=colors_diverging_blue2brown]{colors_diverging_blue2brown()}}, and \code{\link[=new_color_scheme]{new_color_scheme()}}
+}
diff --git a/man/adjust_description.Rd b/man/adjust_description.Rd
index f115bfd2..df22bf4d 100644
--- a/man/adjust_description.Rd
+++ b/man/adjust_description.Rd
@@ -35,3 +35,35 @@ A \code{tidyplot} object
\description{
Adjust description
}
+\details{
+\itemize{
+\item \code{adjust_description()} supports \href{https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath}{plotmath expressions} to include special characters.
+See examples and \href{https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters}{Advanced plotting}.
+}
+}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_description(
+ title = "This is my fantastic plot title",
+ x_axis_title = "Treatment group",
+ y_axis_title = "Disease score",
+ legend_title = "Legend title",
+ caption = "Here goes the caption")
+# Plotmath expressions
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_description(
+ title = "$H[2]*O$",
+ x_axis_title = "$H[2]*O$",
+ y_axis_title = "$H[2]*O$",
+ legend_title = "$H[2]*O$",
+ caption = "$H[2]*O$")
+
+}
diff --git a/man/adjust_font.Rd b/man/adjust_font.Rd
index f744f638..30879b98 100644
--- a/man/adjust_font.Rd
+++ b/man/adjust_font.Rd
@@ -23,3 +23,27 @@ A \code{tidyplot} object
\description{
Adjust font
}
+\examples{
+# Increase font size
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_font(fontsize = 16)
+# Change font family
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_font(family = "mono")
+# Change font face
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_font(face = "bold")
+
+}
diff --git a/man/adjust_legend.Rd b/man/adjust_legend.Rd
index 5294f023..11689983 100644
--- a/man/adjust_legend.Rd
+++ b/man/adjust_legend.Rd
@@ -11,8 +11,8 @@ adjust_legend(plot, title = ggplot2::waiver(), position = "right")
\item{title}{Legend title.}
-\item{position}{The position of legends. Can be one of \code{"none"}, \code{"left"}, \code{"right"},
-\code{"bottom"}, \code{"top"}, or a two-element numeric vector.}
+\item{position}{The position of the legend. Can be one of
+\code{c("right", "left", "bottom", "top", "none")}. Defaults to \code{"right"}.}
}
\value{
A \code{tidyplot} object
@@ -20,3 +20,52 @@ A \code{tidyplot} object
\description{
Adjust legend
}
+\details{
+\itemize{
+\item The \code{title} argument of \code{adjust_legend()} supports \href{https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath}{plotmath expressions} to include special characters.
+See examples and \href{https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters}{Advanced plotting}.
+}
+}
+\examples{
+# New title
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(title = "My new legend title")
+# New title with plotmath expression
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(title = "$E==m*c^{2}$")
+# Alternative legend positions
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(position = "left")
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(position = "top")
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(position = "bottom")
+# `position = "none"` hides the legend
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_legend(position = "none")
+
+}
diff --git a/man/adjust_plot_area_padding.Rd b/man/adjust_plot_area_padding.Rd
index fb4fa0e6..cf2829a5 100644
--- a/man/adjust_plot_area_padding.Rd
+++ b/man/adjust_plot_area_padding.Rd
@@ -38,3 +38,32 @@ A \code{tidyplot} object
\description{
Adjust plot area padding
}
+\examples{
+# Original plot
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding()
+# Increase plot area padding
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding(all = 0.2)
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding(top = 0.8)
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding(bottom = 0.8)
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding(right = 0.8)
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_plot_area_padding(left = 0.8)
+
+}
diff --git a/man/adjust_plot_area_size.Rd b/man/adjust_plot_area_size.Rd
index 234b141f..dd027895 100644
--- a/man/adjust_plot_area_size.Rd
+++ b/man/adjust_plot_area_size.Rd
@@ -21,3 +21,27 @@ A \code{tidyplot} object
\description{
Adjust plot area size
}
+\examples{
+# Resize to 20 x 20 mm
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm(shape = 1) \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_plot_area_size(width = 20, height = 20)
+# Resize to 4 x 4 cm
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm(shape = 1) \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_plot_area_size(width = 4, height = 4, unit = "cm")
+# Remove absolute dimensions and take all available space. This is the ggplot2 default.
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points_beeswarm(shape = 1) \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ adjust_plot_area_size(width = NA, height = NA)
+
+}
diff --git a/man/adjust_x_axis.Rd b/man/adjust_x_axis.Rd
index 6fbafbcd..2a7ba0e5 100644
--- a/man/adjust_x_axis.Rd
+++ b/man/adjust_x_axis.Rd
@@ -85,7 +85,7 @@ You can create your own transformation with \code{\link[scales:new_transform]{sc
\item{force_continuous}{Whether to force the axis to be continuous. Defaults to \code{FALSE}.}
-\item{...}{Arguments passed on to the \code{geom} function.}
+\item{...}{Arguments passed on to ggplot2 \code{scale} function.}
}
\value{
A \code{tidyplot} object
@@ -93,3 +93,48 @@ A \code{tidyplot} object
\description{
Adjust axes
}
+\details{
+\itemize{
+\item The \code{title} argument of \code{adjust_x_axis()} and \code{adjust_y_axis()} supports \href{https://www.rdocumentation.org/packages/grDevices/versions/3.6.2/topics/plotmath}{plotmath expressions} to include special characters.
+See examples and \href{https://jbengler.github.io/tidyplots/articles/Advanced-plotting.html#special-characters}{Advanced plotting}.
+}
+}
+\examples{
+# New titles
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(title = "My new x axis title") \%>\%
+ adjust_y_axis(title = "My new y axis title")
+# New titles with plotmath expressions
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(title = "$H[2]*O$") \%>\%
+ adjust_y_axis(title = "$E==m*c^{2}$")
+# Axes limits
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(limits = c(-1000, 4000)) \%>\%
+ adjust_y_axis(limits = c(-200, 600))
+# Rotate labels
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(rotate_labels = 90) \%>\%
+ adjust_y_axis(rotate_labels = 90)
+# Increase plot area padding
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(padding = c(0.2, 0.2)) \%>\%
+ adjust_y_axis(padding = c(0.2, 0.2))
+# Scale transformation
+animals \%>\%
+ tidyplot(x = weight, y = size, color = number_of_legs) \%>\%
+ add_data_points() \%>\%
+ adjust_x_axis(transform = "log10") \%>\%
+ adjust_y_axis(transform = "log2")
+
+}
diff --git a/man/all_rows.Rd b/man/all_rows.Rd
index 4b6c0e70..93a1ee7c 100644
--- a/man/all_rows.Rd
+++ b/man/all_rows.Rd
@@ -61,3 +61,42 @@ reach \code{n}.}
\description{
Subset data rows
}
+\examples{
+# Highlight all animals
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = all_rows(),
+ color = "red", shape = 1, size = 3)
+# Highlight 3 animals with the highest weight
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = max_rows(weight, n = 3),
+ color = "red", shape = 1, size = 3)
+# Highlight 3 animals with the lowest weight
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = min_rows(weight, n = 3),
+ color = "red", shape = 1, size = 3)
+# Highlight the 3 first animals in the dataset
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = first_rows(n = 3),
+ color = "red", shape = 1, size = 3)
+# Highlight the 3 last animals in the dataset
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = last_rows(n = 3),
+ color = "red", shape = 1, size = 3)
+# Highlight 3 random animals
+animals \%>\%
+ tidyplot(x = weight, y = size) \%>\%
+ add_data_points() \%>\%
+ add_data_points(data = sample_rows(n = 3),
+ color = "red", shape = 1, size = 3)
+
+}
diff --git a/man/as_tidyplot.Rd b/man/as_tidyplot.Rd
index fa8525c6..9dc8930d 100644
--- a/man/as_tidyplot.Rd
+++ b/man/as_tidyplot.Rd
@@ -21,3 +21,12 @@ A \code{tidyplot} object
\description{
Convert ggplot to tidyplot
}
+\examples{
+gg <-
+ study \%>\%
+ ggplot2::ggplot(ggplot2::aes(x = treatment, y = score, color = treatment)) +
+ ggplot2::geom_point()
+gg
+gg \%>\% as_tidyplot()
+
+}
diff --git a/man/figures/lifecycle-archived.svg b/man/figures/lifecycle-archived.svg
new file mode 100644
index 00000000..745ab0c7
--- /dev/null
+++ b/man/figures/lifecycle-archived.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-defunct.svg b/man/figures/lifecycle-defunct.svg
new file mode 100644
index 00000000..d5c9559e
--- /dev/null
+++ b/man/figures/lifecycle-defunct.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg
new file mode 100644
index 00000000..b61c57c3
--- /dev/null
+++ b/man/figures/lifecycle-deprecated.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-experimental.svg b/man/figures/lifecycle-experimental.svg
new file mode 100644
index 00000000..5d88fc2c
--- /dev/null
+++ b/man/figures/lifecycle-experimental.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-maturing.svg b/man/figures/lifecycle-maturing.svg
new file mode 100644
index 00000000..897370ec
--- /dev/null
+++ b/man/figures/lifecycle-maturing.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-questioning.svg b/man/figures/lifecycle-questioning.svg
new file mode 100644
index 00000000..7c1721d0
--- /dev/null
+++ b/man/figures/lifecycle-questioning.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-soft-deprecated.svg b/man/figures/lifecycle-soft-deprecated.svg
new file mode 100644
index 00000000..9c166ff3
--- /dev/null
+++ b/man/figures/lifecycle-soft-deprecated.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/figures/lifecycle-stable.svg b/man/figures/lifecycle-stable.svg
new file mode 100644
index 00000000..9bf21e76
--- /dev/null
+++ b/man/figures/lifecycle-stable.svg
@@ -0,0 +1,29 @@
+
diff --git a/man/figures/lifecycle-superseded.svg b/man/figures/lifecycle-superseded.svg
new file mode 100644
index 00000000..db8d757f
--- /dev/null
+++ b/man/figures/lifecycle-superseded.svg
@@ -0,0 +1,21 @@
+
diff --git a/man/flip_plot.Rd b/man/flip_plot.Rd
index e948dd58..9ba72de1 100644
--- a/man/flip_plot.Rd
+++ b/man/flip_plot.Rd
@@ -15,5 +15,31 @@ flip_plot(plot, ...)
A \code{tidyplot} object
}
\description{
-Flip x and y axis
+\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
+
+This function is superseded because in many cases, \code{flip_plot()} can easily
+be replaced by swapping the \code{x} and \code{y} axis. Some plot components additionally
+require to set the \code{orientation} argument to \code{"y"}.
+}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ flip_plot()
+energy \%>\%
+ tidyplot(x = year, y = power, color = energy_type) \%>\%
+ add_barstack_absolute() \%>\%
+ flip_plot()
+# Better solutions without `flip_plot()`
+study \%>\%
+ tidyplot(x = score, y = treatment, color = treatment) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar()
+energy \%>\%
+ tidyplot(x = power, y = year, color = energy_type) \%>\%
+ add_barstack_absolute(orientation = "y")
+
}
diff --git a/man/format_number.Rd b/man/format_number.Rd
index d88c1242..46793c9e 100644
--- a/man/format_number.Rd
+++ b/man/format_number.Rd
@@ -65,3 +65,12 @@ the horizontal bar of \code{+}.
\description{
Format numbers or p values
}
+\examples{
+format_number(232342.3443)
+format_number(232342.3443, accuracy = 0.01)
+format_number(232342.3443, accuracy = 1, big.mark = "")
+format_p_value(0.03445553)
+format_p_value(0.0003445553)
+format_p_value(0.00003445553)
+
+}
diff --git a/man/rename_x_axis_labels.Rd b/man/rename_x_axis_labels.Rd
index db0e1104..c12c6fdb 100644
--- a/man/rename_x_axis_labels.Rd
+++ b/man/rename_x_axis_labels.Rd
@@ -23,3 +23,34 @@ A \code{tidyplot} object
\description{
Rename axis or color labels
}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ rename_x_axis_labels(new_names = c(
+ "A" = "This",
+ "B" = "is",
+ "C" = "totally",
+ "D" = "new"))
+study \%>\%
+ tidyplot(x = score, y = treatment, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ rename_y_axis_labels(new_names = c(
+ "A" = "This",
+ "B" = "is",
+ "C" = "totally",
+ "D" = "new"))
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ rename_color_labels(new_names = c(
+ "placebo" = "The first",
+ "treatment" = "The second"))
+
+}
diff --git a/man/reorder_x_axis_labels.Rd b/man/reorder_x_axis_labels.Rd
index 24510bdb..76a15579 100644
--- a/man/reorder_x_axis_labels.Rd
+++ b/man/reorder_x_axis_labels.Rd
@@ -23,3 +23,24 @@ A \code{tidyplot} object
\description{
Reorder axis or color labels
}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reorder_x_axis_labels("D", "B")
+study \%>\%
+ tidyplot(x = score, y = treatment, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reorder_y_axis_labels("D", "B")
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reorder_color_labels("treatment")
+
+}
diff --git a/man/reverse_x_axis_labels.Rd b/man/reverse_x_axis_labels.Rd
index bc3739d2..95b54d55 100644
--- a/man/reverse_x_axis_labels.Rd
+++ b/man/reverse_x_axis_labels.Rd
@@ -21,3 +21,24 @@ A \code{tidyplot} object
\description{
Reverse axis or color labels
}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reverse_x_axis_labels()
+study \%>\%
+ tidyplot(x = score, y = treatment, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reverse_y_axis_labels()
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ reverse_color_labels()
+
+}
diff --git a/man/sort_x_axis_labels.Rd b/man/sort_x_axis_labels.Rd
index ff14f798..4dd0fb39 100644
--- a/man/sort_x_axis_labels.Rd
+++ b/man/sort_x_axis_labels.Rd
@@ -23,3 +23,24 @@ A \code{tidyplot} object
\description{
Sort axis or color labels
}
+\examples{
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ sort_x_axis_labels(score)
+study \%>\%
+ tidyplot(x = score, y = treatment, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ sort_y_axis_labels(-score)
+study \%>\%
+ tidyplot(x = treatment, y = score, color = group) \%>\%
+ add_data_points() \%>\%
+ add_mean_bar(alpha = 0.3) \%>\%
+ add_sem_bar() \%>\%
+ sort_color_labels(-score)
+
+}
diff --git a/man/split_plot.Rd b/man/split_plot.Rd
index c1ab9037..64dc797a 100644
--- a/man/split_plot.Rd
+++ b/man/split_plot.Rd
@@ -58,3 +58,11 @@ A \code{tidyplot} object
\description{
Split plot into multiple subplots
}
+\examples{
+energy \%>\%
+ dplyr::filter(year \%in\% c(2005, 2010, 2015, 2020)) \%>\%
+ tidyplot(y = power, color = energy_source) \%>\%
+ add_donut() \%>\%
+ split_plot(by = year)
+
+}
diff --git a/man/tidyplot.Rd b/man/tidyplot.Rd
index fe6d8bc3..a55f7845 100644
--- a/man/tidyplot.Rd
+++ b/man/tidyplot.Rd
@@ -28,3 +28,21 @@ A \code{tidyplot} object
\description{
Create a new tidyplot
}
+\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 = 35, height = 35) \%>\%
+ add_data_points_beeswarm()
+# Change dodge_width
+study \%>\%
+ tidyplot(x = group, y = score, color = dose, dodge_width = 0.3) \%>\%
+ add_mean_bar()
+
+}
diff --git a/man/tidyplots-package.Rd b/man/tidyplots-package.Rd
new file mode 100644
index 00000000..9ecd32d3
--- /dev/null
+++ b/man/tidyplots-package.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/tidyplots-package.R
+\docType{package}
+\name{tidyplots-package}
+\alias{tidyplots}
+\alias{tidyplots-package}
+\title{tidyplots: Tidy Plots Using the Pipe}
+\description{
+The goal of `tidyplots` is to streamline the creation of publication-ready plots for scientific papers, by making it easy to gradually add and refine plot elements. It allows precise control over composition, style, and absolute sizes, while its utilization of the pipe `%>%` simplifies the construction of advanced plotting pipelines.
+}
+\seealso{
+Useful links:
+\itemize{
+ \item \url{https://github.com/jbengler/tidyplots}
+ \item \url{https://jbengler.github.io/tidyplots/}
+ \item Report bugs at \url{https://github.com/jbengler/tidyplots/issues}
+}
+
+}
+\author{
+\strong{Maintainer}: Jan Broder Engler \email{broder.engler@gmail.com} (\href{https://orcid.org/0000-0002-3169-2076}{ORCID}) [copyright holder]
+
+}
+\keyword{internal}
diff --git a/man/time_course.Rd b/man/time_course.Rd
index 9a861b14..42ffe7bb 100644
--- a/man/time_course.Rd
+++ b/man/time_course.Rd
@@ -5,7 +5,7 @@
\alias{time_course}
\title{Time course data}
\format{
-A data frame with.
+A data frame.
}
\source{
tidyplots package