flowchart LR A["<b>Research methods</b><br>Designing studies<br>and collecting data"] --> B["<b>Data wrangling</b><br>Importing, cleaning,<br>checking, reshaping,<br>and visualizing data"] B --> C["<b>Statistical analysis</b><br>Fitting models to<br>answer research questions"] style B stroke-width:3px
Reproducible Data Processing and Visualization
in R and tidyverse
Introduction

This Open Source eBook provides materials for the semester-long Master’s seminar course “Reproducible Data Processing and Visualization in R” that I teach at the University of Bern’s Institute of Psychology.
It is meant to supplement, not replace, what you learn in your other courses. Research methods courses teach you how to design studies that collect the right data, and statistics courses teach you how to analyze that data to answer your research questions. But there is a missing link between the two. The data that real studies produce is rarely ready to be analyzed: it arrives spread across multiple files, in awkward formats, with inconsistent labels, missing values, impossible responses, and participants who need to be excluded. Before any statistical model can be fitted, the data has to be imported, cleaned, checked, reshaped, combined, scored, and visualized. This process is often called data wrangling. It typically takes far more time than the analysis itself, and errors made here flow directly into the results and conclusions. Yet it is rarely taught explicitly. This book focuses on that missing link, and on doing it in a way that is transparent and reproducible.
This book doesn’t teach statistics itself, but two companion books do, both written to build an understanding of the statistical analyses that wrangled data feed into:
- Understanding Statistics Through Monte Carlo Simulations uses simulations to show how statistical methods behave. Its ‘Everything is regression’ chapter explains how correlations, t-tests, ANOVAs, and many other analyses are all linear models in disguise, and can be read without first learning how to simulate data.
- Trustworthiness Assessment and Forensic Meta-Science covers how to understand and interpret p-values, effect sizes such as Cohen’s d, and standard deviations vs. standard errors, and how to check whether published results are trustworthy.
Good data wrangling is about more than getting data into a shape your analysis function will accept. It also means:
- Producing well-structured data: tidy, consistently formatted datasets that are easy to analyze, plot, and combine with other data.
- Making data understandable: clear variable names, sensible labels, and documentation such as codebooks, so that others (and your future self) can tell what each value means.
- Making data ready to share and reuse: datasets and code that others can check, reproduce, and build on, in line with open science practices.
- Protecting participants’ privacy: removing or transforming identifying information before data leave your hands.
- Supporting collaboration: writing readable, well-organized code in structured projects, so that colleagues can review, extend, and work on it with you.
How to use this book
This book is made up of individual Quarto (.qmd) workbooks. Many of the exercises are easiest to complete in your own local copy of these .qmd files.
To run the code locally, I suggest that you download a copy of this book’s code and data from the GitHub repository. If you’re already familiar with GitHub, just clone the repository to your local machine. If you’re not, on the repository page, click the green ‘Code’ button, and then ‘Download ZIP’. Find the .zip file on your hard drive (e.g., Downloads folder) and unzip/decompress the zip files. You’ll find the .qmd files in the chapters/, exercises/ and solutions/ folders.
You can also copy and paste the code for any chapter directly from the website. Click the “</> Code” button on the top right of each page to see the full .qmd file’s code. You can copy and paste this into a .qmd file. However, it’s probably easier to download all the .qmd files and data as mentioned above.
Learning to code is a practice skill. Almost anyone can become competent in writing reproducible code for data processing and visualization with practice. More than anything else, completing this course requires that you practice in your own time, using not only the examples provided but also ones you create yourself. Take real data sets from your own studies, or the thousands available on the Open Science Framework (osf.io), or create simulated messy datasets with my R package {truffle} and practice.

Other learning resources
There are many excellent Open Source resources to learn R and {tidyverse} for data processing and visualization. Readers are encouraged to seek them out to support the materials already provided in this book. I can particularly recommend the following ones:
- Lisa DeBruine and Dale Barr’s Open Source textbook Data Skills for Reproducible Research (DeBruine & Barr, 2021)
- Allison Horst’s interactive web app for learning {dplyr}
- Hadley Wickham and colleagues’ Open Source textbook R For Data Science (aka R4DS) (Wickham et al., 2023)
- Particularly the section on data transformation
- You can complete all the exercises in R4DS with interactive feedback by installing the {r4ds.tutorials} package (
install.packages("r4ds.tutorials")) loading the library (library(r4ds.tutorials)), and going to the “Tutorial” tab in the Environment corner of RStudio. Individual tutorials can be completed alongside the R4DS book, in parallel to this book.
- Garrick Aden-Buie’s tidyexplain gifs for understanding how {tidyr}’s pivot functions work
- datasciencebox.org
- Interactive tutorials that very useful for practicing processing and visualization skills once you’ve already learned the functions (i.e., don’t start here)
- Recorded presentations on many relevant topics
License
© Ian Hussey (2025-2026)
Text and figures are licensed under a Creative Commons Attribution 4.0 (CC BY 4.0) license.
Code is licensed under the MIT License.
You are free to copy, share, adapt, and reuse the contents of this book — text, figures, and code — for any purpose, including commercial use, provided you cite its source. See suggested citation below.
Citation
If you use this book, please cite it as:
Hussey, I. (2026). Reproducible data processing and visualization in R and tidyverse. wrangling.tidyver.se doi: 10.5281/zenodo.19427859
Contributing
If you are interested in contributing to or adapting this eBook, all code and data are available on GitHub.