| Title: | Tidy Plots for Scientific Papers |
|---|---|
| Description: | The goal of 'tidyplots' is to streamline the creation of publication-ready plots for scientific papers. It allows to gradually add, remove and adjust plot components using a consistent and intuitive syntax. |
| Authors: | Jan Broder Engler [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-3169-2076>) |
| Maintainer: | Jan Broder Engler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0.9000 |
| Built: | 2026-06-01 08:01:05 UTC |
| Source: | https://github.com/jbengler/tidyplots |
Add ggplot2 code to a tidyplot
add()add()
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add(ggplot2::geom_point())study |> tidyplot(x = treatment, y = score, color = treatment) |> add(ggplot2::geom_point())
Add annotation
add_annotation_text(plot, text, x, y, fontsize = 7, ...) add_annotation_rectangle( plot, xmin, xmax, ymin, ymax, fill = plot$tidyplot$ink, color = NA, alpha = 0.1, ... ) add_annotation_line(plot, x, xend, y, yend, color = plot$tidyplot$ink, ...)add_annotation_text(plot, text, x, y, fontsize = 7, ...) add_annotation_rectangle( plot, xmin, xmax, ymin, ymax, fill = plot$tidyplot$ink, color = NA, alpha = 0.1, ... ) add_annotation_line(plot, x, xend, y, yend, color = plot$tidyplot$ink, ...)
plot |
A |
text |
String for annotation text. |
x, xmin, xmax, xend, y, ymin, ymax, yend
|
Coordinates for the annotation. |
fontsize |
Font size in points. Defaults to |
... |
Arguments passed on to |
fill |
A hex color for the fill color. For example, |
color |
A hex color for the stroke color. For example, |
alpha |
A |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot() |> add_annotation_text("Look here!", x = 2, y = 25) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_rectangle(xmin = 2.5e5, xmax = Inf, ymin = 42, ymax = Inf) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_rectangle(xmin = 2.5e5, xmax = 6e5, ymin = 42, ymax = 90, color = "#E69F00", fill = NA) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_line(x = 0, xend = Inf, y = 0, yend = Inf)study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot() |> add_annotation_text("Look here!", x = 2, y = 25) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_rectangle(xmin = 2.5e5, xmax = Inf, ymin = 42, ymax = Inf) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_rectangle(xmin = 2.5e5, xmax = 6e5, ymin = 42, ymax = 90, color = "#E69F00", fill = NA) eu_countries |> tidyplot(x = area, y = population) |> add_data_points() |> add_annotation_line(x = 0, xend = Inf, y = 0, yend = Inf)
Add area stack
add_areastack_absolute( plot, linewidth = 0.25, alpha = 0.4, reverse = FALSE, replace_na = FALSE, ... ) add_areastack_relative( plot, linewidth = 0.25, alpha = 0.4, reverse = FALSE, replace_na = FALSE, ... )add_areastack_absolute( plot, linewidth = 0.25, alpha = 0.4, reverse = FALSE, replace_na = FALSE, ... ) add_areastack_relative( plot, linewidth = 0.25, alpha = 0.4, reverse = FALSE, replace_na = FALSE, ... )
plot |
A |
linewidth |
Thickness of the line in points (pt). Typical values range between |
alpha |
A |
reverse |
Whether the order should be reversed or not. Defaults to |
replace_na |
Whether to replace |
... |
Arguments passed on to the |
A tidyplot object.
# for a `count` provide `x` and `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(x = year, color = energy_type) |> add_areastack_absolute() energy |> tidyplot(x = year, color = energy_type) |> add_areastack_relative() # for a `sum` provide `x`, `y` and `color` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_areastack_absolute() energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_areastack_relative() # Flip x and y-axis energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_areastack_absolute(orientation = "y") energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_areastack_relative(orientation = "y")# for a `count` provide `x` and `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(x = year, color = energy_type) |> add_areastack_absolute() energy |> tidyplot(x = year, color = energy_type) |> add_areastack_relative() # for a `sum` provide `x`, `y` and `color` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_areastack_absolute() energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_areastack_relative() # Flip x and y-axis energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_areastack_absolute(orientation = "y") energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_areastack_relative(orientation = "y")
Add bar stack
add_barstack_absolute(plot, width = 0.8, reverse = FALSE, ...) add_barstack_relative(plot, width = 0.8, reverse = FALSE, ...)add_barstack_absolute(plot, width = 0.8, reverse = FALSE, ...) add_barstack_relative(plot, width = 0.8, reverse = FALSE, ...)
plot |
A |
width |
Horizontal width of the plotted object (bar, error bar, boxplot,
violin plot, etc). Typical values range between |
reverse |
Whether the order should be reversed or not. Defaults to |
... |
Arguments passed on to the |
A tidyplot object.
# for a `count` only provide `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(color = energy_type) |> add_barstack_absolute() energy |> tidyplot(color = energy_type) |> add_barstack_relative() # for a `sum` provide `color` and `y` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(y = energy, color = energy_type) |> add_barstack_absolute() energy |> tidyplot(y = energy, color = energy_type) |> add_barstack_relative() # Include variable on second axis energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_barstack_absolute() energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_barstack_relative() # Flip x and y-axis energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_absolute(orientation = "y") energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_relative(orientation = "y")# for a `count` only provide `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(color = energy_type) |> add_barstack_absolute() energy |> tidyplot(color = energy_type) |> add_barstack_relative() # for a `sum` provide `color` and `y` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(y = energy, color = energy_type) |> add_barstack_absolute() energy |> tidyplot(y = energy, color = energy_type) |> add_barstack_relative() # Include variable on second axis energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_barstack_absolute() energy |> tidyplot(x = year, y = energy, color = energy_type) |> add_barstack_relative() # Flip x and y-axis energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_absolute(orientation = "y") energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_relative(orientation = "y")
Add boxplot
add_boxplot( plot, dodge_width = NULL, alpha = 0.3, saturation = 1, show_whiskers = TRUE, show_outliers = TRUE, box_width = 0.6, whiskers_width = 0.8, outlier.size = 0.5, coef = 1.5, outlier.shape = 19, outlier.alpha = 1, linewidth = 0.25, preserve = "total", ... )add_boxplot( plot, dodge_width = NULL, alpha = 0.3, saturation = 1, show_whiskers = TRUE, show_outliers = TRUE, box_width = 0.6, whiskers_width = 0.8, outlier.size = 0.5, coef = 1.5, outlier.shape = 19, outlier.alpha = 1, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
alpha |
A |
saturation |
A |
show_whiskers |
Whether to show boxplot whiskers. Defaults to |
show_outliers |
Whether to show outliers. Defaults to |
box_width |
Width of the boxplot. Defaults to |
whiskers_width |
Width of the whiskers. Defaults to |
outlier.size |
Size of the outliers. Defaults to |
coef |
Length of the whiskers as multiple of IQR. Defaults to 1.5. |
outlier.shape |
Shape of the outliers. Defaults to |
outlier.alpha |
Opacity of the outliers. Defaults to |
linewidth |
Thickness of the line in points (pt). Typical values range between |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot() # Changing arguments: study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(show_whiskers = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(show_outliers = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(box_width = 0.2) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(whiskers_width = 0.2)study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot() # Changing arguments: study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(show_whiskers = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(show_outliers = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(box_width = 0.2) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_boxplot(whiskers_width = 0.2)
Add count
add_count_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_count_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_count_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_count_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_count_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_count_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )add_count_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_count_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_count_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_count_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_count_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_count_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
width |
Horizontal width of the plotted object (bar, error bar, boxplot,
violin plot, etc). Typical values range between |
saturation |
A |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
linewidth |
Thickness of the line in points (pt). Typical values range between |
size |
A |
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale_cut |
Scale cut function to be applied. See |
fontsize |
Font size in points. Defaults to |
extra_padding |
Extra padding to create space for the value label. |
vjust |
Vertical position adjustment of the value label. |
hjust |
Horizontal position adjustment of the value label. |
group |
Variable in the dataset to be used for grouping. |
A tidyplot object.
dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_dash() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_dot() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value() dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_line() dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_area() # Combination dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(alpha = 0.4) |> add_count_dash() |> add_count_dot() |> add_count_value() |> add_count_line() # Changing arguments: alpha # Makes objects transparent dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(saturation = 0.3) # Changing arguments: accuracy dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(accuracy = 1) # Changing arguments: fontsize dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(fontsize = 10) # Changing arguments: color dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(color = "black")dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_dash() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_dot() dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value() dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_line() dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_area() # Combination dinosaurs |> tidyplot(x = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(alpha = 0.4) |> add_count_dash() |> add_count_dot() |> add_count_value() |> add_count_line() # Changing arguments: alpha # Makes objects transparent dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_count_bar(saturation = 0.3) # Changing arguments: accuracy dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(accuracy = 1) # Changing arguments: fontsize dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(fontsize = 10) # Changing arguments: color dinosaurs |> tidyplot(x = time_lived, color = time_lived) |> adjust_x_axis(rotate_labels = TRUE) |> add_count_value(color = "black")
Add curve fit
add_curve_fit( plot, dodge_width = NULL, method = "loess", linewidth = 0.25, alpha = 0.4, preserve = "total", ... )add_curve_fit( plot, dodge_width = NULL, method = "loess", linewidth = 0.25, alpha = 0.4, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
method |
Smoothing method (function) to use, accepts either
For If you have fewer than 1,000 observations but want to use the same |
linewidth |
Thickness of the line in points (pt). Typical values range between |
alpha |
A |
preserve |
Should dodging preserve the |
... |
Arguments passed on to |
A tidyplot object.
time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit() # Changing arguments time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(linewidth = 1) time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(alpha = 0.8) # Remove confidence interval time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(se = FALSE)time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit() # Changing arguments time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(linewidth = 1) time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(alpha = 0.8) # Remove confidence interval time_course |> tidyplot(x = day, y = score, color = treatment) |> add_curve_fit(se = FALSE)
Add data labels
add_data_labels( plot, label, data = all_rows(), fontsize = 7, dodge_width = NULL, jitter_width = 0, jitter_height = 0, preserve = "total", background = FALSE, background_color = NULL, background_alpha = 0.6, label_position = c("below", "above", "left", "right", "center"), seed = 42, ... ) add_data_labels_repel( plot, label, data = all_rows(), fontsize = 7, dodge_width = NULL, jitter_width = 0, jitter_height = 0, preserve = "total", segment.size = 0.2, box.padding = 0.2, max.overlaps = Inf, background = FALSE, background_color = NULL, background_alpha = 0.6, seed = 42, ... )add_data_labels( plot, label, data = all_rows(), fontsize = 7, dodge_width = NULL, jitter_width = 0, jitter_height = 0, preserve = "total", background = FALSE, background_color = NULL, background_alpha = 0.6, label_position = c("below", "above", "left", "right", "center"), seed = 42, ... ) add_data_labels_repel( plot, label, data = all_rows(), fontsize = 7, dodge_width = NULL, jitter_width = 0, jitter_height = 0, preserve = "total", segment.size = 0.2, box.padding = 0.2, max.overlaps = Inf, background = FALSE, background_color = NULL, background_alpha = 0.6, seed = 42, ... )
plot |
A |
label |
Variable in the dataset to be used for the text label. |
data |
The data to be displayed in this layer. There are three options:
|
fontsize |
Font size in points. Defaults to |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
jitter_width |
Amount of random noise to be added to the
horizontal position of the of the data points. This can be useful to deal
with overplotting. Typical values range between |
jitter_height |
Amount of random noise to be added to the
vertical position of the of the data points. This can be useful to deal
with overplotting. Typical values range between |
preserve |
Should dodging preserve the |
background |
Whether to include semitransparent background box behind the labels to improve legibility. Defaults to |
background_color |
Hex color of the background box. The default ( |
background_alpha |
Opacity of the background box. Defaults to |
label_position |
Position of the label in relation to the data point. Can be one of |
seed |
Random seed controlling point and label jitter. |
... |
Arguments passed on to the |
segment.size |
Thickness of the line connecting the label with the data point. Defaults to |
box.padding |
Amount of padding around bounding box, as unit or number.
Defaults to 0.25. (Default unit is lines, but other units can be specified
by passing |
max.overlaps |
Exclude text labels when they overlap too many other things. For each text label, we count how many other text labels or other data points it overlaps, and exclude the text label if it has too many overlaps. Defaults to 10. |
add_data_labels_repel() uses ggrepel::geom_text_repel(). Check there
and in ggrepel examples for
additional arguments.
add_data_labels() and add_data_labels_repel() support data subsetting. See Advanced plotting.
A tidyplot object.
# Create plot and increase padding to make more space for labels p <- animals |> dplyr::slice_head(n = 5) |> tidyplot(x = weight, y = speed) |> theme_ggplot2() |> add_data_points() |> adjust_padding(all = 0.3) # Default label position is `below` the data point p |> add_data_labels(label = animal) # Alternative label positions p |> add_data_labels(label = animal, label_position = "above") p |> add_data_labels(label = animal, label_position = "right") p |> add_data_labels(label = animal, label_position = "left") # Include white background box p |> add_data_labels(label = animal, background = TRUE) p |> add_data_labels(label = animal, background = TRUE, background_color = "pink") # Black labels p |> add_data_labels(label = animal, color = "black") # Use repelling data labels p |> add_data_labels_repel(label = animal, color = "black") p |> add_data_labels_repel(label = animal, color = "black", background = TRUE) p |> add_data_labels_repel(label = animal, color = "black", background = TRUE, min.segment.length = 0)# Create plot and increase padding to make more space for labels p <- animals |> dplyr::slice_head(n = 5) |> tidyplot(x = weight, y = speed) |> theme_ggplot2() |> add_data_points() |> adjust_padding(all = 0.3) # Default label position is `below` the data point p |> add_data_labels(label = animal) # Alternative label positions p |> add_data_labels(label = animal, label_position = "above") p |> add_data_labels(label = animal, label_position = "right") p |> add_data_labels(label = animal, label_position = "left") # Include white background box p |> add_data_labels(label = animal, background = TRUE) p |> add_data_labels(label = animal, background = TRUE, background_color = "pink") # Black labels p |> add_data_labels(label = animal, color = "black") # Use repelling data labels p |> add_data_labels_repel(label = animal, color = "black") p |> add_data_labels_repel(label = animal, color = "black", background = TRUE) p |> add_data_labels_repel(label = animal, color = "black", background = TRUE, min.segment.length = 0)
Add data points
add_data_points( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, dodge_width = NULL, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, ... ) add_data_points_jitter( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, dodge_width = NULL, jitter_width = 0.2, jitter_height = 0, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, seed = 42, ... ) add_data_points_beeswarm( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, cex = 3, corral = "wrap", corral.width = 0.5, dodge_width = NULL, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, ... )add_data_points( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, dodge_width = NULL, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, ... ) add_data_points_jitter( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, dodge_width = NULL, jitter_width = 0.2, jitter_height = 0, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, seed = 42, ... ) add_data_points_beeswarm( plot, data = all_rows(), shape = 19, size = 1, white_border = FALSE, cex = 3, corral = "wrap", corral.width = 0.5, dodge_width = NULL, preserve = "total", rasterize = FALSE, rasterize_dpi = 300, ... )
plot |
A |
data |
The data to be displayed in this layer. There are three options:
|
shape |
An |
size |
A |
white_border |
Whether to include a white border around data points. Defaults to |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
preserve |
Should dodging preserve the |
rasterize |
If |
rasterize_dpi |
The resolution in dots per inch (dpi) used for rastering
the layer if |
... |
Arguments passed on to the |
jitter_width |
Amount of random noise to be added to the
horizontal position of the of the data points. This can be useful to deal
with overplotting. Typical values range between |
jitter_height |
Amount of random noise to be added to the
vertical position of the of the data points. This can be useful to deal
with overplotting. Typical values range between |
seed |
Random seed controlling point and label jitter. |
cex |
Scaling for adjusting point spacing (see |
corral |
Method used to adjust points that would be placed too wide
horizontally. Options are |
corral.width |
Width of the corral, if not |
add_data_points_beeswarm() is based on ggbeeswarm::geom_beeswarm().
Check there for additional arguments.
add_data_points() and friends support rasterization. See examples and Advanced plotting.
add_data_points() and friends support data subsetting. See examples and Advanced plotting.
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_jitter() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() # Changing arguments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_jitter(jitter_width = 1) animals |> tidyplot(x = weight, y = size) |> add_data_points(white_border = TRUE) animals |> tidyplot(x = weight, y = size) |> add_data_points(alpha = 0.4) # Rasterization animals |> tidyplot(x = weight, y = size) |> add_data_points(rasterize = TRUE, rasterize_dpi = 50) # Data subsetting animals |> tidyplot(x = weight, y = size) |> add_data_points() |> add_data_points(data = filter_rows(size > 300), color = "red")study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_jitter() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() # Changing arguments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_jitter(jitter_width = 1) animals |> tidyplot(x = weight, y = size) |> add_data_points(white_border = TRUE) animals |> tidyplot(x = weight, y = size) |> add_data_points(alpha = 0.4) # Rasterization animals |> tidyplot(x = weight, y = size) |> add_data_points(rasterize = TRUE, rasterize_dpi = 50) # Data subsetting animals |> tidyplot(x = weight, y = size) |> add_data_points() |> add_data_points(data = filter_rows(size > 300), color = "red")
Add ellipse
add_ellipse(plot, ...)add_ellipse(plot, ...)
plot |
A |
... |
Arguments passed on to |
A tidyplot object.
pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse() pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse(level = 0.75) pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse(type = "norm")pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse() pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse(level = 0.75) pca |> tidyplot(x = pc1, y = pc2, color = group) |> add_data_points() |> add_ellipse(type = "norm")
Add heatmap
add_heatmap( plot, scale = c("none", "row", "column"), rotate_labels = 90, rasterize = FALSE, rasterize_dpi = 300, ... )add_heatmap( plot, scale = c("none", "row", "column"), rotate_labels = 90, rasterize = FALSE, rasterize_dpi = 300, ... )
plot |
A |
scale |
Whether to compute row z scores for |
rotate_labels |
Degree to rotate the x-axis labels. Defaults to |
rasterize |
If |
rasterize_dpi |
The resolution in dots per inch (dpi) used for rastering
the layer if |
... |
Arguments passed on to the |
add_heatmap() supports rasterization. See examples and Advanced plotting.
A tidyplot object.
climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap() # Calculate row-wise z score climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(scale = "row") # Calculate column-wise z score climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(scale = "column") # Rasterize heatmap climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(rasterize = TRUE, rasterize_dpi = 20)climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap() # Calculate row-wise z score climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(scale = "row") # Calculate column-wise z score climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(scale = "column") # Rasterize heatmap climate |> tidyplot(x = month, y = year, color = max_temperature) |> add_heatmap(rasterize = TRUE, rasterize_dpi = 20)
Add histogram
add_histogram(plot, binwidth = NULL, bins = NULL, ...)add_histogram(plot, binwidth = NULL, bins = NULL, ...)
plot |
A |
binwidth |
The width of the bins. Can be specified as a numeric value
or as a function that takes x after scale transformation as input and
returns a single numeric value. When specifying a function along with a
grouping structure, the function will be called once per group.
The default is to use the number of bins in The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds. |
bins |
Number of bins. Overridden by |
... |
Arguments passed on to the |
A tidyplot object.
energy |> tidyplot(x = energy) |> add_histogram() energy |> tidyplot(x = energy, color = energy_type) |> add_histogram()energy |> tidyplot(x = energy) |> add_histogram() energy |> tidyplot(x = energy, color = energy_type) |> add_histogram()
add_line() and add_area() connect individual data points, which is rarely needed.
In most cases, you are probably looking for add_sum_line(), add_mean_line(), add_sum_area() or add_mean_area().
add_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_area( plot, group, dodge_width = NULL, linewidth = 0.25, alpha = 0.4, preserve = "total", ... )add_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_area( plot, group, dodge_width = NULL, linewidth = 0.25, alpha = 0.4, preserve = "total", ... )
plot |
A |
group |
Variable in the dataset to be used for grouping. |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
linewidth |
Thickness of the line in points (pt). Typical values range between |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
alpha |
A |
A tidyplot object.
# Paired data points study |> tidyplot(x = treatment, y = score, color = group) |> reorder_x_axis_labels("A", "C", "B", "D") |> add_data_points() |> add_line(group = participant, color = "grey") study |> tidyplot(x = treatment, y = score) |> reorder_x_axis_labels("A", "C", "B", "D") |> add_data_points() |> add_area(group = participant)# Paired data points study |> tidyplot(x = treatment, y = score, color = group) |> reorder_x_axis_labels("A", "C", "B", "D") |> add_data_points() |> add_line(group = participant, color = "grey") study |> tidyplot(x = treatment, y = score) |> reorder_x_axis_labels("A", "C", "B", "D") |> add_data_points() |> add_area(group = participant)
Add mean
add_mean_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_mean_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_mean_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_mean_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_mean_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_mean_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )add_mean_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_mean_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_mean_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_mean_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_mean_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_mean_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
width |
Horizontal width of the plotted object (bar, error bar, boxplot,
violin plot, etc). Typical values range between |
saturation |
A |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
linewidth |
Thickness of the line in points (pt). Typical values range between |
size |
A |
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale_cut |
Scale cut function to be applied. See |
fontsize |
Font size in points. Defaults to |
extra_padding |
Extra padding to create space for the value label. |
vjust |
Vertical position adjustment of the value label. |
hjust |
Horizontal position adjustment of the value label. |
group |
Variable in the dataset to be used for grouping. |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value() study |> tidyplot(x = treatment, y = score) |> add_mean_line() study |> tidyplot(x = treatment, y = score) |> add_mean_area() # Combination study |> tidyplot(x = treatment, y = score) |> add_mean_bar(alpha = 0.4) |> add_mean_dash() |> add_mean_dot() |> add_mean_value() |> add_mean_line() # Changing arguments: alpha # Makes objects transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_mean_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_mean_bar(saturation = 0.3) # Changing arguments: accuracy study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(accuracy = 0.01) # Changing arguments: fontsize study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(fontsize = 10) # Changing arguments: color study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(color = "black")study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value() study |> tidyplot(x = treatment, y = score) |> add_mean_line() study |> tidyplot(x = treatment, y = score) |> add_mean_area() # Combination study |> tidyplot(x = treatment, y = score) |> add_mean_bar(alpha = 0.4) |> add_mean_dash() |> add_mean_dot() |> add_mean_value() |> add_mean_line() # Changing arguments: alpha # Makes objects transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_mean_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_mean_bar(saturation = 0.3) # Changing arguments: accuracy study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(accuracy = 0.01) # Changing arguments: fontsize study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(fontsize = 10) # Changing arguments: color study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_value(color = "black")
Add median
add_median_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_median_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_median_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_median_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_median_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_median_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )add_median_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_median_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_median_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_median_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_median_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_median_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
width |
Horizontal width of the plotted object (bar, error bar, boxplot,
violin plot, etc). Typical values range between |
saturation |
A |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
linewidth |
Thickness of the line in points (pt). Typical values range between |
size |
A |
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale_cut |
Scale cut function to be applied. See |
fontsize |
Font size in points. Defaults to |
extra_padding |
Extra padding to create space for the value label. |
vjust |
Vertical position adjustment of the value label. |
hjust |
Horizontal position adjustment of the value label. |
group |
Variable in the dataset to be used for grouping. |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_bar() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_dash() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_dot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value() study |> tidyplot(x = treatment, y = score) |> add_median_line() study |> tidyplot(x = treatment, y = score) |> add_median_area() # Combination study |> tidyplot(x = treatment, y = score) |> add_median_bar(alpha = 0.4) |> add_median_dash() |> add_median_dot() |> add_median_value() |> add_median_line() # Changing arguments: alpha # Makes objects transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_median_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_median_bar(saturation = 0.3) # Changing arguments: accuracy study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(accuracy = 0.01) # Changing arguments: fontsize study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(fontsize = 10) # Changing arguments: color study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(color = "black")study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_bar() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_dash() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_dot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value() study |> tidyplot(x = treatment, y = score) |> add_median_line() study |> tidyplot(x = treatment, y = score) |> add_median_area() # Combination study |> tidyplot(x = treatment, y = score) |> add_median_bar(alpha = 0.4) |> add_median_dash() |> add_median_dot() |> add_median_value() |> add_median_line() # Changing arguments: alpha # Makes objects transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_median_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent study |> tidyplot(x = treatment, y = score, color = treatment) |> theme_minimal_y() |> add_median_bar(saturation = 0.3) # Changing arguments: accuracy study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(accuracy = 0.01) # Changing arguments: fontsize study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(fontsize = 10) # Changing arguments: color study |> tidyplot(x = treatment, y = score, color = treatment) |> add_median_value(color = "black")
Add pie or donut chart
add_pie(plot, width = 1, reverse = FALSE, ...) add_donut(plot, width = 1, reverse = FALSE, ...)add_pie(plot, width = 1, reverse = FALSE, ...) add_donut(plot, width = 1, reverse = FALSE, ...)
plot |
A |
width |
Width of the donut ring. |
reverse |
Whether the order should be reversed or not. Defaults to |
... |
Arguments passed on to the |
A tidyplot object.
# for a `count` only provide `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(color = energy_type) |> add_pie() energy |> tidyplot(color = energy_type) |> add_donut() energy |> tidyplot(color = energy_type) |> add_donut(width = 0.5) # for a `sum` provide `color` and `y` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(y = energy, color = energy_type) |> add_pie() energy |> tidyplot(y = energy, color = energy_type) |> add_donut() energy |> tidyplot(y = energy, color = energy_type) |> add_donut(width = 0.5)# for a `count` only provide `color` # `count` of the data points in each `energy_type` category energy |> tidyplot(color = energy_type) |> add_pie() energy |> tidyplot(color = energy_type) |> add_donut() energy |> tidyplot(color = energy_type) |> add_donut(width = 0.5) # for a `sum` provide `color` and `y` # `sum` of `energy` in each `energy_type` category energy |> tidyplot(y = energy, color = energy_type) |> add_pie() energy |> tidyplot(y = energy, color = energy_type) |> add_donut() energy |> tidyplot(y = energy, color = energy_type) |> add_donut(width = 0.5)
Add reference lines
add_reference_lines( plot, x = NULL, y = NULL, linetype = "dashed", linewidth = 0.25, ... )add_reference_lines( plot, x = NULL, y = NULL, linetype = "dashed", linewidth = 0.25, ... )
plot |
A |
x |
Numeric values where the reference lines should meet the x-axis. For example, |
y |
Numeric values where the reference lines should meet the y-axis. For example, |
linetype |
Either an integer (0-6) or a name (0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash). |
linewidth |
Thickness of the line in points (pt). Typical values range between |
... |
Arguments passed on to the |
A tidyplot object.
animals |> tidyplot(x = weight, y = speed) |> add_reference_lines(x = 4000, y = c(100, 200)) |> add_data_points() animals |> tidyplot(x = weight, y = speed) |> add_reference_lines(x = 4000, y = c(100, 200), linetype = "dotdash") |> add_data_points()animals |> tidyplot(x = weight, y = speed) |> add_reference_lines(x = 4000, y = c(100, 200)) |> add_data_points() animals |> tidyplot(x = weight, y = speed) |> add_reference_lines(x = 4000, y = c(100, 200), linetype = "dotdash") |> add_data_points()
add_sem_errorbar() adds the standard error of mean.
add_range_errorbar() adds the range from smallest to largest value.
add_sd_errorbar() adds the standard deviation.
add_ci95_errorbar() adds the 95% confidence interval.
add_sem_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_range_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_sd_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_ci95_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... )add_sem_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_range_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_sd_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... ) add_ci95_errorbar( plot, dodge_width = NULL, width = 0.4, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
width |
Width of the error bar. |
linewidth |
Thickness of the line in points (pt). Typical values range between |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
A tidyplot object.
# Standard error of the mean study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() # Range from minimum to maximum value study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_range_errorbar() # Standard deviation study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sd_errorbar() # 95% confidence interval study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_ci95_errorbar() # Changing arguments: error bar width study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar(width = 0.8) # Changing arguments: error bar line width study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar(linewidth = 1)# Standard error of the mean study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() # Range from minimum to maximum value study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_range_errorbar() # Standard deviation study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sd_errorbar() # 95% confidence interval study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_ci95_errorbar() # Changing arguments: error bar width study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar(width = 0.8) # Changing arguments: error bar line width study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar(linewidth = 1)
add_sem_ribbon() adds the standard error of mean.
add_range_ribbon() adds the range from smallest to largest value.
add_sd_ribbon() adds the standard deviation.
add_ci95_ribbon() adds the 95% confidence interval.
add_sem_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_range_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_sd_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_ci95_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...)add_sem_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_range_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_sd_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...) add_ci95_ribbon(plot, dodge_width = NULL, alpha = 0.4, color = NA, ...)
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
alpha |
A |
color |
A hex color for the stroke color. For example, |
... |
Arguments passed on to the |
A tidyplot object.
# Standard error of the mean time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sem_ribbon() # Range from minimum to maximum value time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_range_ribbon() # Standard deviation time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sd_ribbon() # 95% confidence interval time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_ci95_ribbon() # Changing arguments: alpha time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sem_ribbon(alpha = 0.7)# Standard error of the mean time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sem_ribbon() # Range from minimum to maximum value time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_range_ribbon() # Standard deviation time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sd_ribbon() # 95% confidence interval time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_ci95_ribbon() # Changing arguments: alpha time_course |> tidyplot(x = day, y = score, color = treatment) |> add_mean_line() |> add_sem_ribbon(alpha = 0.7)
Add sum
add_sum_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_sum_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_sum_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_sum_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_sum_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_sum_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )add_sum_bar( plot, dodge_width = NULL, width = 0.6, saturation = 1, preserve = "total", ... ) add_sum_dash( plot, dodge_width = NULL, width = 0.6, linewidth = 0.25, preserve = "total", ... ) add_sum_dot(plot, dodge_width = NULL, size = 2, preserve = "total", ...) add_sum_value( plot, dodge_width = NULL, accuracy = 0.1, scale_cut = NULL, fontsize = 7, extra_padding = 0.15, vjust = NULL, hjust = NULL, preserve = "total", ... ) add_sum_line( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... ) add_sum_area( plot, group, dodge_width = NULL, linewidth = 0.25, preserve = "total", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
width |
Horizontal width of the plotted object (bar, error bar, boxplot,
violin plot, etc). Typical values range between |
saturation |
A |
preserve |
Should dodging preserve the |
... |
Arguments passed on to the |
linewidth |
Thickness of the line in points (pt). Typical values range between |
size |
A |
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale_cut |
Scale cut function to be applied. See |
fontsize |
Font size in points. Defaults to |
extra_padding |
Extra padding to create space for the value label. |
vjust |
Vertical position adjustment of the value label. |
hjust |
Horizontal position adjustment of the value label. |
group |
Variable in the dataset to be used for grouping. |
A tidyplot object.
spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_dash() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_dot() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value() spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_line() spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_area() # Combination spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_median_bar(alpha = 0.4) |> add_median_dash() |> add_median_dot() |> add_median_value() |> add_median_line() # Changing arguments: alpha # Makes objects transparent spendings |> tidyplot(x = category, y = amount, color = category) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent spendings |> tidyplot(x = category, y = amount, color = category) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar(saturation = 0.3) # Changing arguments: accuracy spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(accuracy = 1) # Changing arguments: fontsize spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(fontsize = 10) # Changing arguments: color spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(color = "black") # Changing arguments: extra_padding spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(extra_padding = 0.5)spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_dash() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_dot() spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value() spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_line() spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_area() # Combination spendings |> tidyplot(x = category, y = amount) |> adjust_x_axis(rotate_labels = TRUE) |> add_median_bar(alpha = 0.4) |> add_median_dash() |> add_median_dot() |> add_median_value() |> add_median_line() # Changing arguments: alpha # Makes objects transparent spendings |> tidyplot(x = category, y = amount, color = category) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar(alpha = 0.4) # Changing arguments: saturation # Reduces fill color saturation without making the object transparent spendings |> tidyplot(x = category, y = amount, color = category) |> theme_minimal_y() |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_bar(saturation = 0.3) # Changing arguments: accuracy spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(accuracy = 1) # Changing arguments: fontsize spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(fontsize = 10) # Changing arguments: color spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(color = "black") # Changing arguments: extra_padding spendings |> tidyplot(x = category, y = amount, color = category) |> adjust_x_axis(rotate_labels = TRUE) |> add_sum_value(extra_padding = 0.5)
Add statistical test
add_test_pvalue( plot, padding_top = 0.15, method = "t_test", p.adjust.method = "none", ref.group = NULL, comparisons = NULL, paired_by = NULL, label = "{tidyplots::format_p_value(p.adj, 0.0001)}", label.size = 7/ggplot2::.pt, step.increase = 0.15, vjust = -0.25, bracket.nudge.y = 0.1, hide.ns = FALSE, p.adjust.by = "panel", symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**", "*", "ns")), color = plot$tidyplot$ink, hide_info = FALSE, ... ) add_test_asterisks( plot, padding_top = 0.1, method = "t_test", p.adjust.method = "none", ref.group = NULL, comparisons = NULL, paired_by = NULL, label = "p.adj.signif", label.size = 10/ggplot2::.pt, step.increase = 0.2, vjust = 0.3, bracket.nudge.y = 0.15, hide.ns = TRUE, p.adjust.by = "panel", symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**", "*", "ns")), color = plot$tidyplot$ink, hide_info = FALSE, ... )add_test_pvalue( plot, padding_top = 0.15, method = "t_test", p.adjust.method = "none", ref.group = NULL, comparisons = NULL, paired_by = NULL, label = "{tidyplots::format_p_value(p.adj, 0.0001)}", label.size = 7/ggplot2::.pt, step.increase = 0.15, vjust = -0.25, bracket.nudge.y = 0.1, hide.ns = FALSE, p.adjust.by = "panel", symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**", "*", "ns")), color = plot$tidyplot$ink, hide_info = FALSE, ... ) add_test_asterisks( plot, padding_top = 0.1, method = "t_test", p.adjust.method = "none", ref.group = NULL, comparisons = NULL, paired_by = NULL, label = "p.adj.signif", label.size = 10/ggplot2::.pt, step.increase = 0.2, vjust = 0.3, bracket.nudge.y = 0.15, hide.ns = TRUE, p.adjust.by = "panel", symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**", "*", "ns")), color = plot$tidyplot$ink, hide_info = FALSE, ... )
plot |
A |
padding_top |
Extra padding above the data points to accommodate the statistical comparisons. |
method |
a character string indicating which method to be used for
pairwise comparisons. Default is |
p.adjust.method |
method for adjusting p values (see
|
ref.group |
a character string or a numeric value specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).
Allowed values can be:
|
comparisons |
A list of length-2 vectors. The entries in the vector are 2 integers that correspond to the index of the groups of interest, to be compared. |
paired_by |
Variable to be used for paired analysis. |
label |
character string specifying label. Can be:
. |
label.size |
change the size of the label text |
step.increase |
numeric vector with the increase in fraction of total height for every additional comparison to minimize overlap. |
vjust |
move the text up or down relative to the bracket. |
bracket.nudge.y |
Vertical adjustment to nudge brackets by (in fraction of the total height). Useful to move up or move down the bracket. If positive value, brackets will be moved up; if negative value, brackets are moved down. |
hide.ns |
can be logical value ( |
p.adjust.by |
possible value is one of |
symnum.args |
a list of arguments to pass to the function
In other words, we use the following convention for symbols indicating statistical significance:
|
color |
A hex color for the stroke color. For example, |
hide_info |
Whether to hide details about the statistical testing as caption. Defaults to |
... |
Arguments passed on to |
add_test_pvalue() and add_test_asterisks() use ggpubr::geom_pwc().
Check there for additional arguments.
Known limitation: add_test_pvalue() and add_test_asterisks() expect a
discrete variable on the x-axis and a continuous variable on the y-axis.
To produce horizontal plots, use flip_plot().
A tidyplot object.
# Add p value study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue() # Add asterisks study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks() # Change stat method study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(method = "wilcoxon") # Change p.adjust method study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(p.adjust.method = "bonferroni") # Define reference group to test against study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks(ref.group = 1) # Define selected comparisons study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(comparisons = list(c(1,3),c(2,4))) # Paired analysis x <- c(2.3, 4.5, 6.3, 3.4, 7.8, 6.7) df <- data.frame( x = c(x, x + c(0.8, 0.75)), group = paste0("g", rep(c(1, 2), each = 6)), batch = paste0("b", c(1:6, 1:6)), shuffle = paste0("c", c(1:6, 6:1)) ) df |> tidyplot(group, x, color = group) |> add_boxplot() |> add_data_points() |> add_test_pvalue(paired_by = shuffle) |> add_line(group = shuffle, color = "black") df |> tidyplot(group, x, color = group) |> add_boxplot() |> add_data_points() |> add_test_pvalue(paired_by = batch) |> add_line(group = batch, color = "black") # hide non-significant p values gene_expression |> # filter to one gene dplyr::filter(external_gene_name == "Apol6") |> # start plotting tidyplot(x = condition, y = expression, color = sample_type) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(hide.ns = TRUE) # Adjust top padding for statistical comparisons study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(padding_top = 0.08) # Hide stats information study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(hide_info = TRUE)# Add p value study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue() # Add asterisks study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks() # Change stat method study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(method = "wilcoxon") # Change p.adjust method study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(p.adjust.method = "bonferroni") # Define reference group to test against study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks(ref.group = 1) # Define selected comparisons study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(comparisons = list(c(1,3),c(2,4))) # Paired analysis x <- c(2.3, 4.5, 6.3, 3.4, 7.8, 6.7) df <- data.frame( x = c(x, x + c(0.8, 0.75)), group = paste0("g", rep(c(1, 2), each = 6)), batch = paste0("b", c(1:6, 1:6)), shuffle = paste0("c", c(1:6, 6:1)) ) df |> tidyplot(group, x, color = group) |> add_boxplot() |> add_data_points() |> add_test_pvalue(paired_by = shuffle) |> add_line(group = shuffle, color = "black") df |> tidyplot(group, x, color = group) |> add_boxplot() |> add_data_points() |> add_test_pvalue(paired_by = batch) |> add_line(group = batch, color = "black") # hide non-significant p values gene_expression |> # filter to one gene dplyr::filter(external_gene_name == "Apol6") |> # start plotting tidyplot(x = condition, y = expression, color = sample_type) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(hide.ns = TRUE) # Adjust top padding for statistical comparisons study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(padding_top = 0.08) # Hide stats information study |> tidyplot(x = dose, y = score, color = group) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue(hide_info = TRUE)
Add pre-computed statistics
add_test_pvalue_manual( plot, data, padding_top = 0.15, label = "{tidyplots::format_p_value(p, 0.0001)}", label.size = 7/ggplot2::.pt, y.position = "y.position", xmin = "group1", xmax = "group2", step.increase = 0.15, vjust = -0.25, bracket.nudge.y = 0.1, bracket.size = 0.3, tip.length = 0.03, hide.ns = FALSE, remove.bracket = FALSE, color = plot$tidyplot$ink, ... ) add_test_asterisks_manual( plot, data, padding_top = 0.1, label = "p.signif", label.size = 10/ggplot2::.pt, y.position = "y.position", xmin = "group1", xmax = "group2", step.increase = 0.2, vjust = 0.3, bracket.nudge.y = 0.15, bracket.size = 0.3, tip.length = 0.03, hide.ns = TRUE, remove.bracket = FALSE, color = plot$tidyplot$ink, ... )add_test_pvalue_manual( plot, data, padding_top = 0.15, label = "{tidyplots::format_p_value(p, 0.0001)}", label.size = 7/ggplot2::.pt, y.position = "y.position", xmin = "group1", xmax = "group2", step.increase = 0.15, vjust = -0.25, bracket.nudge.y = 0.1, bracket.size = 0.3, tip.length = 0.03, hide.ns = FALSE, remove.bracket = FALSE, color = plot$tidyplot$ink, ... ) add_test_asterisks_manual( plot, data, padding_top = 0.1, label = "p.signif", label.size = 10/ggplot2::.pt, y.position = "y.position", xmin = "group1", xmax = "group2", step.increase = 0.2, vjust = 0.3, bracket.nudge.y = 0.15, bracket.size = 0.3, tip.length = 0.03, hide.ns = TRUE, remove.bracket = FALSE, color = plot$tidyplot$ink, ... )
plot |
A |
data |
a data frame containing statitistical test results. The expected
default format should contain the following columns: |
padding_top |
Extra padding above the data points to accommodate the statistical comparisons. |
label |
the column containing the label (e.g.: label = "p" or label =
"p.adj"), where |
label.size |
Font size of label text. |
y.position |
column containing the coordinates (in data units) to be used for absolute positioning of the label. Default value is "y.position". Can be also a numeric vector. |
xmin |
column containing the position of the left sides of the brackets. Default value is "group1". |
xmax |
(optional) column containing the position of the right sides of the brackets. Default value is "group2". If NULL, the p-values are plotted as a simple text. |
step.increase |
numeric vector with the increase in fraction of total height for every additional comparison to minimize overlap. |
vjust |
move the text up or down relative to the bracket. Can be also a column name available in the data. |
bracket.nudge.y |
Vertical adjustment to nudge brackets by. Useful to move up or move down the bracket. If positive value, brackets will be moved up; if negative value, brackets are moved down. |
bracket.size |
Width of the lines of the bracket. |
tip.length |
numeric vector with the fraction of total height that the bar goes down to indicate the precise column. Default is 0.03. |
hide.ns |
can be logical value or a character vector.
|
remove.bracket |
logical, if |
color |
text and line color. Can be variable name in the data for coloring by groups. |
... |
Arguments passed on to |
add_test_pvalue_manual() and add_test_asterisks_manual() use
ggpubr::stat_pvalue_manual(). Check there for additional arguments.
These functions take pre-computed statistics as input via the data parameter.
Known limitation: add_test_pvalue_manual() and add_test_asterisks_manual() expect a
discrete variable on the x-axis and a continuous variable on the y-axis.
To produce horizontal plots, use flip_plot().
A tidyplot object.
# Add manual p-values from pre-computed statistics stat_df <- data.frame( group1 = "A", group2 = "B", p = 0.025, p.signif = "*", y.position = 50 ) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue_manual(data = stat_df) # Add manual asterisks study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks_manual(data = stat_df)# Add manual p-values from pre-computed statistics stat_df <- data.frame( group1 = "A", group2 = "B", p = 0.025, p.signif = "*", y.position = 50 ) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_pvalue_manual(data = stat_df) # Add manual asterisks study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points() |> add_test_asterisks_manual(data = stat_df)
Add plot title or caption
add_title(plot, title = ggplot2::waiver()) add_caption(plot, caption = ggplot2::waiver())add_title(plot, title = ggplot2::waiver()) add_caption(plot, caption = ggplot2::waiver())
plot |
A |
title |
Title of the plot. |
caption |
Caption of the plot. |
add_title() and add_caption() support plotmath expressions to include special characters.
See examples and Advanced plotting.
A tidyplot object.
study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_title("This is my title") study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_caption("This is the fine print in the caption") # Plotmath expression study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_title("$H[2]*O~and~E==m*c^{2}$")study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_title("This is my title") study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_caption("This is the fine print in the caption") # Plotmath expression study |> tidyplot(x = treatment, y = score) |> add_data_points_beeswarm() |> add_title("$H[2]*O~and~E==m*c^{2}$")
Add violin plot
add_violin( plot, dodge_width = NULL, alpha = 0.3, saturation = 1, trim = TRUE, linewidth = 0.25, scale = "width", ... )add_violin( plot, dodge_width = NULL, alpha = 0.3, saturation = 1, trim = TRUE, linewidth = 0.25, scale = "width", ... )
plot |
A |
dodge_width |
For adjusting the distance between grouped objects. Defaults
to |
alpha |
A |
saturation |
A |
trim |
If |
linewidth |
Thickness of the line in points (pt). Typical values range between |
scale |
if "area" (default), all violins have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. If "width", all violins have the same maximum width. |
... |
Arguments passed on to the |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin() # Changing arguments: study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(saturation = 0.6) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(draw_quantiles = c(0.25, 0.5, 0.75)) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(trim = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(linewidth = 1)study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin() # Changing arguments: study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(saturation = 0.6) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(draw_quantiles = c(0.25, 0.5, 0.75)) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(trim = FALSE) study |> tidyplot(x = treatment, y = score, color = treatment) |> add_violin(linewidth = 1)
Adjust colors
adjust_colors( plot, new_colors = NULL, saturation = 1, labels = tidyplot_parse_labels(), downsample = c("evenly", "first", "last", "middle"), ... )adjust_colors( plot, new_colors = NULL, saturation = 1, labels = tidyplot_parse_labels(), downsample = c("evenly", "first", "last", "middle"), ... )
plot |
A |
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. |
saturation |
A |
labels |
One of the options below. Please note that when
|
downsample |
If too many colors are provided, whether to downsample |
... |
Arguments passed on to the ggplot2 |
A tidyplot object.
colors_discrete_friendly(), colors_continuous_viridis(), colors_diverging_blue2brown(), and new_color_scheme()
# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Provide hex colors study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_colors(new_colors = colors_discrete_seaside) # Provide named vector study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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)# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Provide hex colors study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_colors(new_colors = colors_discrete_seaside) # Provide named vector study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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)
Adjust font
adjust_font(plot, fontsize = 7, family = NULL, face = NULL)adjust_font(plot, fontsize = 7, family = NULL, face = NULL)
plot |
A |
fontsize |
Font size in points. Defaults to |
family |
The typeface to use. The validity of this value will depend on
the graphics device being used for rendering the plot. See
the systemfonts vignette
for guidance on the best way to access fonts installed on your computer.
The values |
face |
Font face ("plain", "italic", "bold", "bold.italic") |
A tidyplot object.
# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Increase font size study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(fontsize = 16) # Change font family study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(family = "mono") # Change font face study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(face = "bold")# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Increase font size study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(fontsize = 16) # Change font family study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(family = "mono") # Change font face study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_font(face = "bold")
Adjust legend
adjust_legend_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_legend_position(plot, position = "right")adjust_legend_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_legend_position(plot, position = "right")
plot |
A |
title |
Legend title. |
fontsize |
Font size in points. Defaults to |
family |
The typeface to use. The validity of this value will depend on
the graphics device being used for rendering the plot. See
the systemfonts vignette
for guidance on the best way to access fonts installed on your computer.
The values |
face |
Font face ("plain", "italic", "bold", "bold.italic") |
color |
A hex color for the stroke color. For example, |
... |
Arguments passed on to |
position |
The position of the legend. Can be one of
|
The title argument of adjust_legend_title() supports plotmath expressions to include special characters.
See examples and Advanced plotting.
A tidyplot object.
# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # New title study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_legend_position("left") study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_legend_position("top") study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_legend_position("none")# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # New title study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_legend_position("left") study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_legend_position("top") study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> 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.4) |> add_sem_errorbar() |> adjust_legend_position("none")
Adjust plot area padding
adjust_padding( plot, top = NA, right = NA, bottom = NA, left = NA, all = NA, force_continuous = FALSE, ... )adjust_padding( plot, top = NA, right = NA, bottom = NA, left = NA, all = NA, force_continuous = FALSE, ... )
plot |
A |
top |
Extra space between the data points and the top. Defaults to |
right |
Extra space between the data points and the right. Defaults to |
bottom |
Extra space between the data points and the bottom. Defaults to |
left |
Extra space between the data points and the left. Defaults to |
all |
Extra space around the data pointst. Overwrites |
force_continuous |
Whether to force the axis to be continuous. Defaults to |
... |
Arguments passed on to the |
A tidyplot object.
# Plot without adjustments animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding() # Increase plot area padding animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(all = 0.2) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(top = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(bottom = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(right = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(left = 0.8)# Plot without adjustments animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding() # Increase plot area padding animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(all = 0.2) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(top = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(bottom = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(right = 0.8) animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() |> adjust_padding(left = 0.8)
Adjust plot area size
adjust_size( plot, width = NULL, height = NULL, unit = NULL, overall_width = NULL, overall_height = NULL )adjust_size( plot, width = NULL, height = NULL, unit = NULL, overall_width = NULL, overall_height = NULL )
plot |
A |
width, height
|
Dimensions of the plot area. The default ( |
unit |
Unit of the plot area width and height. The default ( |
overall_width, overall_height
|
The overall dimensions of a multiplot layout generated with |
A tidyplot object.
# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm(shape = 1) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Resize to 15 x 15 mm study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm(shape = 1) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_size(width = 15, height = 15) # 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.4) |> add_sem_errorbar() |> adjust_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.4) |> add_sem_errorbar() |> adjust_size(width = NA, height = NA)# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm(shape = 1) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Resize to 15 x 15 mm study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm(shape = 1) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_size(width = 15, height = 15) # 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.4) |> add_sem_errorbar() |> adjust_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.4) |> add_sem_errorbar() |> adjust_size(width = NA, height = NA)
This function is a wrapper around ggplot2::theme(). To use the required theme
helper functions ggplot2::element_blank(), ggplot2::element_rect(),
ggplot2::element_line(), and ggplot2::element_text() you need to either load
the ggplot2 package via library(ggplot2) or use the ggplot2:: prefix as shown above.
adjust_theme_details(plot, ...)adjust_theme_details(plot, ...)
plot |
A |
... |
Arguments passed on to the |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> adjust_theme_details(plot.background = ggplot2::element_rect(fill = "#FFEBFF"))study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points_beeswarm() |> add_mean_bar(alpha = 0.4) |> adjust_theme_details(plot.background = ggplot2::element_rect(fill = "#FFEBFF"))
Adjust titles and caption
adjust_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_x_axis_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_y_axis_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_caption( plot, caption = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... )adjust_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_x_axis_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_y_axis_title( plot, title = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... ) adjust_caption( plot, caption = ggplot2::waiver(), fontsize = NULL, family = NULL, face = NULL, color = NULL, ... )
plot |
A |
title |
Plot or axes title. |
fontsize |
Font size in points. Defaults to |
family |
The typeface to use. The validity of this value will depend on
the graphics device being used for rendering the plot. See
the systemfonts vignette
for guidance on the best way to access fonts installed on your computer.
The values |
face |
Font face ("plain", "italic", "bold", "bold.italic") |
color |
A hex color for the stroke color. For example, |
... |
Arguments passed on to |
caption |
Plot caption. |
Adjust the plot title, axis titles and caption
All functions support plotmath expressions to include special characters. See examples and Advanced plotting.
A tidyplot object.
# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Adjust description study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_title("This is my fantastic plot title") |> adjust_x_axis_title("Treatment group") |> adjust_y_axis_title("Disease score") |> adjust_legend_title("Legend title") |> adjust_caption("Here goes the caption") # Plotmath expressions study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_title("$H[2]*O$") |> adjust_x_axis_title("$H[2]*O$") |> adjust_y_axis_title("$H[2]*O$") |> adjust_legend_title("$H[2]*O$") |> adjust_caption("$H[2]*O$")# Plot without adjustments study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Adjust description study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_title("This is my fantastic plot title") |> adjust_x_axis_title("Treatment group") |> adjust_y_axis_title("Disease score") |> adjust_legend_title("Legend title") |> adjust_caption("Here goes the caption") # Plotmath expressions study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> adjust_title("$H[2]*O$") |> adjust_x_axis_title("$H[2]*O$") |> adjust_y_axis_title("$H[2]*O$") |> adjust_legend_title("$H[2]*O$") |> adjust_caption("$H[2]*O$")
Adjust axes
adjust_x_axis( plot, title = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = NULL, limits = NULL, padding = c(NA, NA), rotate_labels = FALSE, transform = "identity", cut_short_scale = FALSE, force_continuous = FALSE, ... ) adjust_y_axis( plot, title = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = NULL, limits = NULL, padding = c(NA, NA), rotate_labels = FALSE, transform = "identity", cut_short_scale = FALSE, force_continuous = FALSE, ... )adjust_x_axis( plot, title = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = NULL, limits = NULL, padding = c(NA, NA), rotate_labels = FALSE, transform = "identity", cut_short_scale = FALSE, force_continuous = FALSE, ... ) adjust_y_axis( plot, title = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = NULL, limits = NULL, padding = c(NA, NA), rotate_labels = FALSE, transform = "identity", cut_short_scale = FALSE, force_continuous = FALSE, ... )
plot |
A |
title |
Axis title. |
breaks |
One of:
|
labels |
One of the options below. Please note that when
|
limits |
Axis limits. For example, with |
padding |
Extra space between the data points and the axes. Defaults to |
rotate_labels |
Whether to rotate axis labels. If |
transform |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
cut_short_scale |
Whether to shorten axis labels using |
force_continuous |
Whether to force the axis to be continuous. Defaults to |
... |
Arguments passed on to ggplot2 |
The title argument of adjust_x_axis() and adjust_y_axis() supports plotmath expressions to include special characters.
See examples and Advanced plotting.
A tidyplot object.
# Plot without adjustments animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() # New titles animals |> tidyplot(x = weight, y = size, color = family) |> 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 = family) |> 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 = family) |> 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 = family) |> 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 = family) |> 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 = family) |> add_data_points() |> adjust_x_axis(transform = "log10") |> adjust_y_axis(transform = "log2")# Plot without adjustments animals |> tidyplot(x = weight, y = size, color = family) |> add_data_points() # New titles animals |> tidyplot(x = weight, y = size, color = family) |> 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 = family) |> 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 = family) |> 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 = family) |> 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 = family) |> 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 = family) |> add_data_points() |> adjust_x_axis(transform = "log10") |> adjust_y_axis(transform = "log2")
Subset data rows
all_rows() filter_rows(..., .by = NULL) max_rows(order_by, n, by = NULL, with_ties = TRUE, na_rm = FALSE) min_rows(order_by, n, by = NULL, with_ties = TRUE, na_rm = FALSE) first_rows(n, by = NULL) last_rows(n, by = NULL) sample_rows(n, by = NULL)all_rows() filter_rows(..., .by = NULL) max_rows(order_by, n, by = NULL, with_ties = TRUE, na_rm = FALSE) min_rows(order_by, n, by = NULL, with_ties = TRUE, na_rm = FALSE) first_rows(n, by = NULL) last_rows(n, by = NULL) sample_rows(n, by = NULL)
... |
< |
.by, by
|
< |
order_by |
< |
n |
The number of rows to select. If not are supplied, A negative value of |
with_ties |
Should ties be kept together? The default, |
na_rm |
Should missing values in |
A function to achieve the desired data subsetting.
# 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 first 3 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 last 3 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)# 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 first 3 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 last 3 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)
Animals data
animalsanimals
A data frame.
ChatGPT-3.5, Caution: The accuracy of the data has not been verified.
dplyr::glimpse(animals)dplyr::glimpse(animals)
Climate data
climateclimate
A data frame.
National Oceanic and Atmospheric Administration, Temperature data, weather station Hamburg Fuhlsbüttel, Germany
dplyr::glimpse(climate)dplyr::glimpse(climate)
For more information about the use of color schemes in tidyplots, check out this article: Color schemes
colors_continuous_viridis colors_continuous_magma colors_continuous_inferno colors_continuous_plasma colors_continuous_cividis colors_continuous_rocket colors_continuous_mako colors_continuous_turbo colors_continuous_bluepinkyellowcolors_continuous_viridis colors_continuous_magma colors_continuous_inferno colors_continuous_plasma colors_continuous_cividis colors_continuous_rocket colors_continuous_mako colors_continuous_turbo colors_continuous_bluepinkyellow
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 265.
An object of class tidycolor (inherits from character) of length 11.
Color schemes can be conveniently previewed by using the print method of the
tidycolor class. This will send a html preview to the RStudio Viewer pane.
colors_continuous_viridis
colors_continuous_magma
colors_continuous_inferno
colors_continuous_plasma
colors_continuous_cividis
colors_continuous_rocket
colors_continuous_mako
colors_continuous_turbo
colors_continuous_bluepinkyellow
For more information about the use of color schemes in tidyplots, check out this article: Color schemes
colors_discrete_friendly colors_discrete_seaside colors_discrete_apple colors_discrete_friendly_long colors_discrete_okabeito colors_discrete_ibm colors_discrete_metro colors_discrete_candy colors_discrete_alger colors_discrete_rainbowcolors_discrete_friendly colors_discrete_seaside colors_discrete_apple colors_discrete_friendly_long colors_discrete_okabeito colors_discrete_ibm colors_discrete_metro colors_discrete_candy colors_discrete_alger colors_discrete_rainbow
An object of class tidycolor (inherits from character) of length 6.
An object of class tidycolor (inherits from character) of length 5.
An object of class tidycolor (inherits from character) of length 7.
An object of class tidycolor (inherits from character) of length 7.
An object of class tidycolor (inherits from character) of length 7.
An object of class tidycolor (inherits from character) of length 5.
An object of class tidycolor (inherits from character) of length 5.
An object of class tidycolor (inherits from character) of length 5.
An object of class tidycolor (inherits from character) of length 5.
An object of class tidycolor (inherits from character) of length 9.
The signature theme of tidyplots colors_discrete_friendly was adapted from
the Okabe & Ito color palette that was designed
to work well for people with color vision deficiency.
Color schemes can be conveniently previewed by using the print method of the
tidycolor class. This will send a html preview to the RStudio Viewer pane.
colors_discrete_friendly
colors_discrete_seaside
colors_discrete_apple
colors_discrete_friendly_long
colors_discrete_okabeito
colors_discrete_ibm
colors_discrete_metro
colors_discrete_candy
colors_discrete_alger
colors_discrete_rainbow
For more information about the use of color schemes in tidyplots, check out this article: Color schemes
colors_diverging_blue2red colors_diverging_blue2brown colors_diverging_BuRd colors_diverging_BuYlRd colors_diverging_spectral colors_diverging_icefirecolors_diverging_blue2red colors_diverging_blue2brown colors_diverging_BuRd colors_diverging_BuYlRd colors_diverging_spectral colors_diverging_icefire
An object of class tidycolor (inherits from character) of length 17.
An object of class tidycolor (inherits from character) of length 17.
An object of class tidycolor (inherits from character) of length 11.
An object of class tidycolor (inherits from character) of length 11.
An object of class tidycolor (inherits from character) of length 96.
An object of class tidycolor (inherits from character) of length 96.
Color schemes can be conveniently previewed by using the print method of the
tidycolor class. This will send a html preview to the RStudio Viewer pane.
colors_diverging_blue2red
colors_diverging_blue2brown
colors_diverging_BuRd
colors_diverging_BuYlRd
colors_diverging_spectral
colors_diverging_icefire
Dinosaurs data
dinosaursdinosaurs
A data frame.
ChatGPT-3.5, Caution: The accuracy of the data has not been verified.
dplyr::glimpse(dinosaurs)dplyr::glimpse(dinosaurs)
Distributions data
distributionsdistributions
A data frame.
tidyplots package
dplyr::glimpse(distributions)dplyr::glimpse(distributions)
Energy data
energyenergy
A data frame.
Energy-Charts, Energy production data, Germany
dplyr::glimpse(energy)dplyr::glimpse(energy)
Energy week data
energy_weekenergy_week
A data frame.
Energy-Charts, Energy production data, Germany
dplyr::glimpse(energy_week)dplyr::glimpse(energy_week)
EU countries data
eu_countrieseu_countries
A data frame.
ChatGPT-3.5, Caution: The accuracy of the data has not been verified.
dplyr::glimpse(eu_countries)dplyr::glimpse(eu_countries)
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".
flip_plot(plot, ...)flip_plot(plot, ...)
plot |
A |
... |
Arguments passed on to |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> flip_plot() energy |> tidyplot(x = year, y = energy, 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.4) |> add_sem_errorbar() energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_absolute(orientation = "y")study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> flip_plot() energy |> tidyplot(x = year, y = energy, 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.4) |> add_sem_errorbar() energy |> tidyplot(x = energy, y = year, color = energy_type) |> add_barstack_absolute(orientation = "y")
Format p values
format_p_value(x, accuracy = 1e-04)format_p_value(x, accuracy = 1e-04)
x |
A |
accuracy |
A number to round to. For example, use |
Formatted number as character string.
format_p_value(0.03445553) format_p_value(0.0003445553) format_p_value(0.00003445553)format_p_value(0.03445553) format_p_value(0.0003445553) format_p_value(0.00003445553)
RNA-Seq expression data
gene_expressiongene_expression
A data frame.
Bassoon proteinopathy drives neurodegeneration in multiple sclerosis, Nature Neuroscience 2019
GSE104899, Gene Expression Omnibus
dplyr::glimpse(gene_expression)dplyr::glimpse(gene_expression)
For more information about the use of color schemes in tidyplots, check out this article: Color schemes
new_color_scheme(x, name = "Untitled color scheme", reverse = FALSE)new_color_scheme(x, name = "Untitled color scheme", reverse = FALSE)
x |
Character vector of hex colors. For example |
name |
Name of the custom color scheme. |
reverse |
Whether the order should be reversed or not. Defaults to |
A tidyplot object.
new_color_scheme(c("#ECA669","#E06681","#8087E2","#E2D269")) new_color_scheme(c("#ECA669","#E06681","#8087E2","#E2D269"), name = "my_custom_color_scheme")new_color_scheme(c("#ECA669","#E06681","#8087E2","#E2D269")) new_color_scheme(c("#ECA669","#E06681","#8087E2","#E2D269"), name = "my_custom_color_scheme")
Principle component analysis data
pcapca
A data frame.
Bassoon proteinopathy drives neurodegeneration in multiple sclerosis, Nature Neuroscience 2019
dplyr::glimpse(pca)dplyr::glimpse(pca)
Remove plot area clipping
remove_clipping(plot)remove_clipping(plot)
plot |
A |
A tidyplot object.
# Before removing spendings |> tidyplot(x = amount, y = category, color = category) |> add_sum_bar(alpha = 0.2) |> add_sum_dash() |> add_sum_value(accuracy = 1, color = "black") # After removing spendings |> tidyplot(x = amount, y = category, color = category) |> add_sum_bar(alpha = 0.2) |> add_sum_dash() |> add_sum_value(accuracy = 1, color = "black") |> remove_clipping()# Before removing spendings |> tidyplot(x = amount, y = category, color = category) |> add_sum_bar(alpha = 0.2) |> add_sum_dash() |> add_sum_value(accuracy = 1, color = "black") # After removing spendings |> tidyplot(x = amount, y = category, color = category) |> add_sum_bar(alpha = 0.2) |> add_sum_dash() |> add_sum_value(accuracy = 1, color = "black") |> remove_clipping()
Remove legend or legend title
remove_legend(plot) remove_legend_title(plot)remove_legend(plot) remove_legend_title(plot)
plot |
A |
A tidyplot object.
# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_legend_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_legend()# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_legend_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_legend()
Remove plot area padding
remove_padding(plot, force_continuous = FALSE)remove_padding(plot, force_continuous = FALSE)
plot |
A |
force_continuous |
Whether to force the axis to be continuous. Defaults to |
A tidyplot object.
# Before removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() # After removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> remove_padding()# Before removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() # After removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> remove_padding()
Remove plot title or caption
remove_title(plot) remove_caption(plot)remove_title(plot) remove_caption(plot)
plot |
A |
A tidyplot object.
# Before removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") # After removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") |> remove_title() animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") |> remove_caption()# Before removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") # After removing animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") |> remove_title() animals |> tidyplot(x = weight, y = speed, color = family) |> add_data_points() |> add_title("Name of the plot") |> add_caption("This is the caption") |> remove_caption()
Remove x-axis or parts of it
remove_x_axis(plot) remove_x_axis_line(plot) remove_x_axis_ticks(plot) remove_x_axis_labels(plot) remove_x_axis_title(plot)remove_x_axis(plot) remove_x_axis_line(plot) remove_x_axis_ticks(plot) remove_x_axis_labels(plot) remove_x_axis_title(plot)
plot |
A |
A tidyplot object.
# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_line() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_ticks() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_labels() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis()# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_line() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_ticks() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_labels() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_x_axis()
Remove y-axis or parts of it
remove_y_axis(plot) remove_y_axis_line(plot) remove_y_axis_ticks(plot) remove_y_axis_labels(plot) remove_y_axis_title(plot)remove_y_axis(plot) remove_y_axis_line(plot) remove_y_axis_ticks(plot) remove_y_axis_labels(plot) remove_y_axis_title(plot)
plot |
A |
A tidyplot object.
# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_line() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_ticks() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_labels() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis()# Before removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() # After removing study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_line() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_ticks() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_labels() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis_title() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar() |> remove_y_axis()
Rename axis or color levels
rename_x_axis_levels(plot, new_names) rename_y_axis_levels(plot, new_names) rename_color_levels(plot, new_names)rename_x_axis_levels(plot, new_names) rename_y_axis_levels(plot, new_names) rename_color_levels(plot, new_names)
plot |
A |
new_names |
Named character vector in the format c("old1" = "new1", "old2" = "new2"). |
A tidyplot object.
# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_x_axis_levels(new_names = c( "A" = "This", "B" = "is", "C" = "totally", "D" = "new")) # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_y_axis_levels(new_names = c( "A" = "This", "B" = "is", "C" = "totally", "D" = "new")) # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_color_levels(new_names = c( "high" = "Sky high", "low" = "Deep low"))# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_x_axis_levels(new_names = c( "A" = "This", "B" = "is", "C" = "totally", "D" = "new")) # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_y_axis_levels(new_names = c( "A" = "This", "B" = "is", "C" = "totally", "D" = "new")) # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Rename color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> rename_color_levels(new_names = c( "high" = "Sky high", "low" = "Deep low"))
Reorder axis or color levels
reorder_x_axis_levels(plot, ...) reorder_y_axis_levels(plot, ...) reorder_color_levels(plot, ...)reorder_x_axis_levels(plot, ...) reorder_y_axis_levels(plot, ...) reorder_color_levels(plot, ...)
plot |
A |
... |
Arguments passed on to |
A tidyplot object.
# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_x_axis_levels("D", "B", "A") # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_y_axis_levels("D", "B", "A") # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_color_levels("low")# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_x_axis_levels("D", "B", "A") # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_y_axis_levels("D", "B", "A") # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reorder color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reorder_color_levels("low")
Reverse axis or color levels
reverse_x_axis_levels(plot) reverse_y_axis_levels(plot) reverse_color_levels(plot)reverse_x_axis_levels(plot) reverse_y_axis_levels(plot) reverse_color_levels(plot)
plot |
A |
A tidyplot object.
# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_x_axis_levels() # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_y_axis_levels() # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_color_levels()# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse x-axis levels study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_x_axis_levels() # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse y-axis levels study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_y_axis_levels() # Before adjustment study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Reverse color levels study |> tidyplot(x = group, y = score, color = dose) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> reverse_color_levels()
This function takes a plot or list of plots and writes them to a (multipage) file.
save_plot( plot = ggplot2::last_plot(), filename, width = NA, height = NA, units = c("mm", "cm", "in"), padding = 0.1, multiple_files = FALSE, view_plot = TRUE, ... )save_plot( plot = ggplot2::last_plot(), filename, width = NA, height = NA, units = c("mm", "cm", "in"), padding = 0.1, multiple_files = FALSE, view_plot = TRUE, ... )
plot |
Plot to save, defaults to last plot displayed. |
filename |
File name to create on disk. |
width, height
|
Dimensions of the graphic device to save the plot.
Defaults to |
units |
Units of length. Defaults to |
padding |
Extra space around the saved plot. Defaults to |
multiple_files |
Whether to save multiple pages as individual files. |
view_plot |
Whether to view the plot on screen after saving. |
... |
Other arguments passed on to the graphics device function,
as specified by |
Handling of file dimensions. Output file dimensions are determined according the the following precedence.
The width and height arguments.
Dimensions inferred from the incoming plot object with absolute dimensions.
System default device dimensions.
A tidyplot object.
# Save plot to file study |> tidyplot(treatment, score) |> add_data_points() |> save_plot("single_plot.pdf") # Save intermediate stages to file study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> add_data_points_beeswarm() |> save_plot("before.pdf") |> adjust_colors(colors_discrete_seaside) |> save_plot("after.pdf") # Save multipage PDF file gene_expression |> dplyr::slice_head(n = 160) |> tidyplot(group, expression, color = sample_type) |> add_data_points() |> adjust_size(width = 30, height = 25) |> split_plot(by = external_gene_name, nrow = 2, ncol = 2) |> save_plot("multipage_plot.pdf") # Save multiple PDF files gene_expression |> dplyr::slice_head(n = 160) |> tidyplot(group, expression, color = sample_type) |> add_data_points() |> adjust_size(width = 30, height = 25) |> split_plot(by = external_gene_name, nrow = 2, ncol = 2) |> save_plot("plot.pdf", multiple_files = TRUE)# Save plot to file study |> tidyplot(treatment, score) |> add_data_points() |> save_plot("single_plot.pdf") # Save intermediate stages to file study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> add_data_points_beeswarm() |> save_plot("before.pdf") |> adjust_colors(colors_discrete_seaside) |> save_plot("after.pdf") # Save multipage PDF file gene_expression |> dplyr::slice_head(n = 160) |> tidyplot(group, expression, color = sample_type) |> add_data_points() |> adjust_size(width = 30, height = 25) |> split_plot(by = external_gene_name, nrow = 2, ncol = 2) |> save_plot("multipage_plot.pdf") # Save multiple PDF files gene_expression |> dplyr::slice_head(n = 160) |> tidyplot(group, expression, color = sample_type) |> add_data_points() |> adjust_size(width = 30, height = 25) |> split_plot(by = external_gene_name, nrow = 2, ncol = 2) |> save_plot("plot.pdf", multiple_files = TRUE)
Sort axis or color levels
sort_x_axis_levels(plot, ..., .fun = NULL, .reverse = FALSE) sort_y_axis_levels(plot, ..., .fun = NULL, .reverse = FALSE) sort_color_levels(plot, ..., .fun = NULL, .reverse = FALSE)sort_x_axis_levels(plot, ..., .fun = NULL, .reverse = FALSE) sort_y_axis_levels(plot, ..., .fun = NULL, .reverse = FALSE) sort_color_levels(plot, ..., .fun = NULL, .reverse = FALSE)
plot |
A |
... |
Optional variables to use for sorting. |
.fun |
Override the function used for sorting. Is automatically determined from the plot. |
.reverse |
Whether the order should be reversed or not. Defaults to |
A tidyplot object.
# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort x-axis levels by score study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_x_axis_levels() # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort y-axis levels by score study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_y_axis_levels() # Before adjustment study |> tidyplot(x = group, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort color levels by score study |> tidyplot(x = group, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_color_levels()# Before adjustments study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort x-axis levels by score study |> tidyplot(x = treatment, y = score) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_x_axis_levels() # Before adjustments study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort y-axis levels by score study |> tidyplot(x = score, y = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_y_axis_levels() # Before adjustment study |> tidyplot(x = group, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() # Sort color levels by score study |> tidyplot(x = group, y = score, color = treatment) |> add_data_points() |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> sort_color_levels()
Spending data
spendingsspendings
A data frame.
tidyplots package
dplyr::glimpse(spendings)dplyr::glimpse(spendings)
Split plot into multiple subplots
split_plot( plot, by = NULL, rows = NULL, cols = NULL, ncol = NULL, nrow = NULL, axes = "all", axis.titles = "all", scales = NULL, ... )split_plot( plot, by = NULL, rows = NULL, cols = NULL, ncol = NULL, nrow = NULL, axes = "all", axis.titles = "all", scales = NULL, ... )
plot |
A |
by |
One variable that should be used for splitting. |
rows, cols
|
Two variables that should be used for splitting, representing rows and columns, respectively. |
ncol, nrow
|
The number of columns and rows per page. Only takes effect when using |
axes |
Determines which axes will be drawn in case of fixed scales.
When |
axis.titles |
Determines which axis titles will be drawn.
When |
scales |
Should scales be fixed |
... |
Arguments passed on to the |
A tidyplot object.
# Before splitting energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) # Split by year energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) |> split_plot(by = year) # Change dimensions of subplots energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 15, height = 15) |> split_plot(by = year) # Spread plots across multiple pages energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) |> split_plot(by = year, ncol = 2, nrow = 1) # Split by two variables energy |> dplyr::mutate(decade = paste0(floor(year / 10) * 10, "s")) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(14,14) |> split_plot(rows = decade, cols = energy_type)# Before splitting energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) # Split by year energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) |> split_plot(by = year) # Change dimensions of subplots energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 15, height = 15) |> split_plot(by = year) # Spread plots across multiple pages energy |> dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(width = 25, height = 25) |> split_plot(by = year, ncol = 2, nrow = 1) # Split by two variables energy |> dplyr::mutate(decade = paste0(floor(year / 10) * 10, "s")) |> tidyplot(y = energy, color = energy_source) |> add_donut() |> adjust_size(14,14) |> split_plot(rows = decade, cols = energy_type)
Study data
studystudy
A data frame.
tidyplots package
dplyr::glimpse(study)dplyr::glimpse(study)
Themes
theme_tidyplot(plot, fontsize = 7) theme_ggplot2(plot, fontsize = 7) theme_minimal_xy(plot, fontsize = 7) theme_minimal_x(plot, fontsize = 7) theme_minimal_y(plot, fontsize = 7)theme_tidyplot(plot, fontsize = 7) theme_ggplot2(plot, fontsize = 7) theme_minimal_xy(plot, fontsize = 7) theme_minimal_x(plot, fontsize = 7) theme_minimal_y(plot, fontsize = 7)
plot |
A |
fontsize |
Font size in points. Defaults to |
A tidyplot object.
study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_tidyplot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_ggplot2() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_xy() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_x() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_y()study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_tidyplot() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_ggplot2() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_xy() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_x() study |> tidyplot(x = treatment, y = score, color = treatment) |> add_data_points() |> add_sem_errorbar() |> add_mean_dash() |> theme_minimal_y()
Create a new tidyplot
tidyplot( data, ..., width = NULL, height = NULL, unit = NULL, dodge_width = NULL, my_style = NULL, paper = NULL, ink = NULL )tidyplot( data, ..., width = NULL, height = NULL, unit = NULL, dodge_width = NULL, my_style = NULL, paper = NULL, ink = NULL )
data |
A tidy |
... |
Mappings for the |
width, height
|
Dimensions of the plot area. The default ( |
unit |
Unit of the plot area width and height. The default ( |
dodge_width |
For adjusting the distance between grouped objects.
The default ( |
my_style |
Styling function to apply to the plot. The default ( |
paper |
Background color. The default ( |
ink |
Foreground color. The default ( |
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()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()
Control the settings for formatting tidyplots globally.
tidyplots_options( width = NULL, height = NULL, unit = NULL, dodge_width = NULL, my_style = NULL, paper = NULL, ink = NULL )tidyplots_options( width = NULL, height = NULL, unit = NULL, dodge_width = NULL, my_style = NULL, paper = NULL, ink = NULL )
width, height
|
Dimensions of the plot area. The default ( |
unit |
Unit of the plot area width and height. The default ( |
dodge_width |
For adjusting the distance between grouped objects.
The default ( |
my_style |
Styling function to apply to the plot. The default ( |
paper |
Background color. The default ( |
ink |
Foreground color. The default ( |
The old options invisibly
# Define custom style my_style <- function(x) x |> adjust_colors(colors_discrete_candy) |> adjust_font(family = "mono") # Set tidyplots options tidyplots_options( width = 3, height = 4, unit = "cm", dodge_width = 1, my_style = my_style ) # Plot study |> tidyplot(x = group, y = score, color = dose) |> add_mean_bar() # Reset tidyplots options tidyplots_options() # Same plot study |> tidyplot(x = group, y = score, color = dose) |> add_mean_bar()# Define custom style my_style <- function(x) x |> adjust_colors(colors_discrete_candy) |> adjust_font(family = "mono") # Set tidyplots options tidyplots_options( width = 3, height = 4, unit = "cm", dodge_width = 1, my_style = my_style ) # Plot study |> tidyplot(x = group, y = score, color = dose) |> add_mean_bar() # Reset tidyplots options tidyplots_options() # Same plot study |> tidyplot(x = group, y = score, color = dose) |> add_mean_bar()
Time course data
time_coursetime_course
A data frame.
tidyplots package
dplyr::glimpse(time_course)dplyr::glimpse(time_course)
View plot on screen
view_plot(plot, data = all_rows(), title = ggplot2::waiver(), ...)view_plot(plot, data = all_rows(), title = ggplot2::waiver(), ...)
plot |
A |
data |
The data to be displayed in this layer. There are three options:
|
title |
Plot title. |
... |
Arguments passed on to |
view_plot() supports data subsetting. See examples and Advanced plotting.
A tidyplot object.
# View intermediate stages on screen study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> add_data_points_beeswarm() |> view_plot(title = "Before changing color scheme") |> adjust_colors(colors_discrete_seaside) |> view_plot(title = "After changing color scheme") # View data subsets on screen gene_expression |> tidyplot(x = condition, y = expression, color = sample_type) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points_beeswarm() |> view_plot(data = filter_rows(external_gene_name == "Apol6"), title = "Apol6") |> view_plot(data = filter_rows(external_gene_name == "Bsn"), title = "Bsn")# View intermediate stages on screen study |> tidyplot(x = treatment, y = score, color = treatment) |> add_mean_bar(alpha = 0.4) |> add_sem_errorbar() |> add_data_points_beeswarm() |> view_plot(title = "Before changing color scheme") |> adjust_colors(colors_discrete_seaside) |> view_plot(title = "After changing color scheme") # View data subsets on screen gene_expression |> tidyplot(x = condition, y = expression, color = sample_type) |> add_mean_dash() |> add_sem_errorbar() |> add_data_points_beeswarm() |> view_plot(data = filter_rows(external_gene_name == "Apol6"), title = "Apol6") |> view_plot(data = filter_rows(external_gene_name == "Bsn"), title = "Bsn")