Teaching Statistics with R — Interactive Lesson

Sample lesson kit for instructors

Teaching statistics with R

R lets students see an idea happen: simulate it, plot it, change one number and watch the result move. This page models four ways to use it in a classroom. Each tab pairs a live demo with the R code that would produce it.

What R offers a classroom

Free and reproducible

No licence cost for students. A script records every step, so a result can be rerun and checked by anyone.

RStudio and Posit Cloud

A friendly editor with console, plots and file panes. Cloud workspaces avoid install problems on day one.

R Markdown and Quarto

Code, output and explanation live in one document. Students submit a report that regenerates its own figures.

learnr and swirl

Interactive tutorials with exercises, hints and auto-graded answers, inside the browser or the R console.

Shiny apps

Turn a concept into a slider-driven app, like the demos on these tabs, and share it with a link.

webR

R running directly in the browser through WebAssembly, so a class can run code with nothing installed.

A four-week sample unit

Week 1: Look at dataLoad a built-in dataset with mtcars or iris. Use str(), summary() and hist(). Goal: describe a distribution in words.
Week 2: Simulate to understand samplingUse replicate() and rnorm() to build sampling distributions. Goal: explain why sample means vary and how sample size changes that.
Week 3: Model relationshipsFit lm(), plot with abline(), read residuals. Goal: interpret slope and R² for a real question.
Week 4: CommunicateWrangle with dplyr, plot with ggplot2, and write a one-page Quarto report. Goal: a reproducible analysis someone else can rerun.

Teaching tip: ask students to predict the result before they run code. Prediction followed by surprise is where most of the learning happens.