Explaining
Analysis Steps in R
Learn to communicate your data analysis pipeline clearly: describe transformations, justify choices, and make your R code tell a story.
What Does Explaining Analysis Steps Mean?
When you write R code to analyze data, you make dozens of decisions: filtering rows, creating new columns, choosing summary statistics, and more. Explaining analysis steps means describing what each transformation does, why you chose it, and how it connects to your overall question.
Why Clear Explanations Matter
Anatomy of an Analysis Pipeline
The Three-Part Explanation Framework
Comments vs. Explanations
| Code Comment | Analysis Explanation | |
|---|---|---|
| Location | Inside the .R file | In a report, notebook, or presentation |
| Audience | Future you / other coders | Stakeholders, teachers, reviewers |
| Depth | Brief: "remove NAs" | Full: What + Why + How |
| Example | # filter adults | "We filter for \( \text{age} > 18 \) to match the study population, using dplyr::filter()." |
Step-by-Step Checklist
Example 1: Simple Filtering
Example 2: Multi-Step Pipeline
Example 3: Explaining a Visualization
The Pipe %>% as a Narrative Tool
R's pipe operator %>% (or the base R pipe |>) chains operations in the order you think about them. This makes your code read like a story: "Start with X, then do Y, then do Z."
Writing Explanations in R Markdown
R Markdown (.Rmd) and Quarto (.qmd) files let you weave code and text together. Your explanation lives right next to the code it describes, making the analysis self-documenting.
Describing Transformations Precisely
Vague language leads to confusion. Use precise verbs that match the R function you used:
| Vague | Precise | R Function |
|---|---|---|
| "Cleaned the data" | "Removed 12 rows with missing values in the income column" | filter(!is.na(income)) |
| "Changed the variable" | "Log-transformed price to reduce right skew" | mutate(log_price = log(price)) |
| "Looked at averages" | "Computed mean and standard deviation of score, grouped by class" | group_by() %>% summarize() |
Justifying Your Choices
Every decision in your pipeline is a choice. Strong explanations include reasoning, not just description. Here are common choices and how to justify them:
Common Mistakes
Summary of Explanation Strategies
| Strategy | When to Use | Key Phrase |
|---|---|---|
| What + Why + How | Every pipeline step | "We [verb] [object] because [reason], using [function]." |
| Precise Verbs | Describing transformations | "Filtered," "mutated," "grouped," "summarized" |
| Justify Choices | Non-obvious decisions | "We chose X over Y because..." |
| State Assumptions | Statistical steps | "This assumes that..." |
| Pipe Narration | Multi-step chains | "Start with... then... then..." |
Question 1 of 5
Which of the following best explains a filtering step?
Question 2 of 5
What are the three components of the explanation framework taught in this lesson?
Question 3 of 5
A student writes the following explanation for their analysis:
"First I loaded the data. Then I cleaned it. Then I made a graph. The graph shows the results."
What is the biggest weakness of this explanation?
Question 4 of 5
Why is R's pipe operator %>% helpful when explaining analysis steps?
Question 5 of 5
A student explains: "We used median instead of mean for income because the distribution is right-skewed." Which part of the framework does "because the distribution is right-skewed" represent?