Learn R Programming

⚠️There's a newer version (0.2.2) of this package.Take me there.

tidyplots

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.

Installation

You can install the released version of tidyplots from CRAN with:

install.packages("tidyplots")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("jbengler/tidyplots")

Usage

Here are some examples. Also have a look at the getting started guide and the full documentation.

library(tidyplots)

study %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_bar(alpha = 0.4) %>% 
  add_sem_errorbar() %>% 
  add_data_points_beeswarm()
energy %>% 
  tidyplot(x = year, y = energy, color = energy_source) %>% 
  add_barstack_absolute()
energy %>% 
  dplyr::filter(year %in% c(2005, 2010, 2015, 2020)) %>% 
  tidyplot(y = energy, color = energy_source) %>% 
  add_donut() %>% 
  split_plot(by = year)
energy_week %>% 
  tidyplot(x = date, y = power, color = energy_source) %>% 
  add_areastack_absolute()
energy_week %>% 
  tidyplot(x = date, y = power, color = energy_source) %>% 
  add_areastack_relative()
study %>% 
  tidyplot(x = group, y = score, color = dose) %>% 
  add_mean_bar(alpha = 0.4) %>% 
  add_mean_dash() %>% 
  add_mean_value()
time_course %>%
  tidyplot(x = day, y = score, color = treatment) %>%
  add_mean_line() %>%
  add_mean_dot() %>%
  add_sem_ribbon()
climate %>%
  tidyplot(x = month, y = year, color = max_temperature) %>%
  add_heatmap()
study %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_boxplot() %>% 
  add_test_pvalue(ref.group = 1)
gene_expression %>% 
  dplyr::filter(external_gene_name %in% c("Apol6", "Col5a3", "Vgf", "Bsn")) %>% 
  tidyplot(x = condition, y = expression, color = sample_type) %>% 
  add_mean_dash() %>% 
  add_sem_errorbar() %>% 
  add_data_points_beeswarm() %>% 
  add_test_asterisks(hide_info = TRUE) %>% 
  remove_x_axis_title() %>% 
  split_plot(by = external_gene_name)
study %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_bar(alpha = 0.4) %>% 
  add_sem_errorbar() %>% 
  add_data_points_beeswarm() %>% 
  view_plot(title = "Default color scheme: 'friendly'") %>% 
  adjust_colors(colors_discrete_apple) %>% 
  view_plot(title = "Alternative color scheme: 'apple'")

Documentation

Acknowledgements

I would like to thank Lars Binkle-Ladisch for our insightful discussions and for consistently challenging my decisions regarding the naming of functions and their arguments.

Many thanks to the R and tidyverse communities. tidyplots is built upon their software and coding paradigms, and it would not have been possible without their contributions.

tidyplots relies on several fantastic packages that handle all the heavy lifting behind the scenes. These include cli, dplyr, forcats, ggbeeswarm, ggplot2, ggpubr, ggrastr, ggrepel, glue, Hmisc, htmltools, lifecycle, patchwork, purrr, rlang, scales, stringr, tidyr, and tidyselect.

Copy Link

Version

Install

install.packages('tidyplots')

Monthly Downloads

2,765

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jan Broder Engler

Last Published

January 19th, 2025

Functions in tidyplots (0.2.1)

add_sem_errorbar

Add error bar
add_pie

Add pie or donut chart
add_histogram

Add histogram
add_sum_bar

Add sum
add_mean_bar

Add mean
add_line

Add line or area
add_sem_ribbon

Add ribbon
add_test_pvalue

Add statistical test
add_reference_lines

Add reference lines
add_median_bar

Add median
add_title

Add plot title or caption
adjust_legend_title

Adjust legend
adjust_padding

Adjust plot area padding
adjust_size

Adjust plot area size
adjust_theme_details

Adjust theme details
adjust_font

Adjust font
adjust_colors

Adjust colors
add_violin

Add violin plot
adjust_x_axis

Adjust axes
adjust_title

Adjust titles and caption
colors_continuous_viridis

Continuous color schemes
as_tidyplot

Convert ggplot to tidyplot
all_rows

Subset data rows
distributions

Distributions data
colors_diverging_blue2red

Diverging color schemes
flip_plot

Flip x and y-axis
remove_legend

Remove legend or legend title
remove_y_axis

Remove y-axis or parts of it
format_number

Format numbers or p values
climate

Climate data
dinosaurs

Dinosaurs data
animals

Animals data
common_arguments

Common arguments
gene_expression

RNA-Seq expression data
energy_week

Energy week data
colors_discrete_friendly

Discrete color schemes
remove_title

Remove plot title or caption
remove_padding

Remove plot area padding
%>%

The pipe
energy

Energy data
eu_countries

EU countries data
new_color_scheme

New color scheme
remove_x_axis

Remove x-axis or parts of it
reorder_x_axis_labels

Reorder axis or color labels
save_plot

Save plots to file
split_plot

Split plot into multiple subplots
spendings

Spending data
tidyplot

Create a new tidyplot
sort_x_axis_labels

Sort axis or color labels
rename_x_axis_labels

Rename axis or color labels
study

Study data
tidyplots-package

tidyplots: Tidy Plots for Scientific Papers
reverse_x_axis_labels

Reverse axis or color labels
theme_tidyplot

Themes
view_plot

View plot on screen
time_course

Time course data
add_areastack_absolute

Add area stack
add_annotation_text

Add annotation
add_data_labels

Add data labels
add_data_points

Add data points
add_barstack_absolute

Add bar stack
add

Add ggplot2 code to a tidyplot
add_count_bar

Add count
add_heatmap

Add heatmap
add_boxplot

Add boxplot
add_curve_fit

Add curve fit