01 / 21
R >

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.

R Programming

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

Reproducibility
Others can re-run your analysis and get the same results.
Trust
Reviewers, teachers, and collaborators trust work they can follow.
Debugging
When something breaks, clear steps help you find the error fast.

Anatomy of an Analysis Pipeline

Raw Data Clean & Filter Transform Model /Plot What: Import CSV Why: Source dataset read_csv("data.csv") What: Remove NAs Why: Ensure accuracy filter(!is.na(x)) What: Log-transform Why: Reduce skew mutate(log_x = log(x)) Each step gets a What + Why + How annotation Pipeline Step Explanation Card

The Three-Part Explanation Framework

1
WHAT: Name the operation. "Filter rows where \( \text{age} > 18 \)" or "Group by region and summarize mean income."
2
WHY: Justify the choice. "We remove minors because the study only applies to adults" or "Grouping reveals regional patterns."
3
HOW: Reference the R function. "Using filter() from dplyr" or "Using group_by() %>% summarize()."

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

1
State the goal. What question are you trying to answer with this analysis?
2
Describe your data source. Where does the data come from? How many rows/columns?
3
List each transformation in order using the What + Why + How framework.
4
Note any assumptions. Did you assume normality? Did you drop outliers? Say so.
5
Summarize the result. What did the final output tell you about your original question?

Example 1: Simple Filtering

# Goal: Find average test score for seniors library(dplyr) students %>% filter(grade == 12) %>% summarize(avg_score = mean(test_score, na.rm = TRUE))

Example 2: Multi-Step Pipeline

# Goal: Compare median income by region library(dplyr) census %>% filter(!is.na(income)) %>% mutate(income_k = income / 1000) %>% group_by(region) %>% summarize(med_income = median(income_k))

Example 3: Explaining a Visualization

# Goal: Visualize score distribution by grade library(ggplot2) ggplot(students, aes(x = test_score, fill = factor(grade))) + geom_histogram(bins = 20, alpha = 0.7, position = "identity") + labs(title = "Test Score Distribution")

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."

Nested (hard to read)
summarize(filter(df, \(x > 0\)), m=mean(y))
Piped (reads naturally)
df %>% filter(\(x > 0\)) %>% summarize(...)
Each %>% is a sentence in your analysis narrative "Take df, then filter positives, then compute the mean."

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.

Markdown Text
Write your What + Why in plain English between code chunks.
Code Chunks
Wrap R code in ```{r} blocks. The How is the code itself.
Output
Tables, plots, and values render inline to support your claims.

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:

1
Choosing median over mean: "The distribution is right-skewed, so the median better represents the typical value."
2
Removing outliers: "Values above \( 3\sigma \) from the mean are likely data-entry errors, affecting \( < 1\% \) of rows."
3
Using a log transform: "The raw data spans several orders of magnitude; \( \log(x) \) compresses the scale for clearer visualization."

Common Mistakes

✕ Restating Code as English
"We used filter to filter" adds nothing. Explain what was filtered and why.
✕ Skipping the "Why"
Listing steps without justification. Readers need to know your reasoning, not just your actions.
✕ Out-of-Order Explanations
Describing step 3 before step 1. Match your explanation to the pipeline order.

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

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?