Assignment 1: Getting Started with R
Due by 11:59 PM on Sunday, April 5, 2026
Assigned: Wednesday, April 1 (Session 2) Due: Sunday, April 5 at 11:59 PM Submit: R script (.R file) on Canvas
See the step-by-step guides: Setting Up an R Project | Using R Scripts
Overview
This assignment gets you comfortable with RStudio and introduces you to creating visualizations with ggplot2. You’ll work with the built-in mpg dataset to create your first plots.
Setup
- Open RStudio and your
psy410project - Create a new R script: File → New File → R Script
- Save it as
assignment-01-YOURNAME.R - At the top of your script, add:
# Assignment 1: Getting Started with R
# Your Name
# Date
library(tidyverse)Tasks
Task 1: Explore the data (10 points)
Use the mpg dataset (loaded automatically with tidyverse).
Use
glimpse()to look at the structure ofmpg. In a comment, note how many rows and columns there are.Use
?mpgto read the documentation. In a comment, explain whatdisplandhwyrepresent.
Task 2: Create a basic scatterplot (15 points)
Create a scatterplot showing the relationship between engine displacement (displ) and highway fuel efficiency (hwy).
Your plot should:
- Have displacement on the x-axis
- Have highway mpg on the y-axis
- Include a clear title
- Have labeled axes (not just variable names)
Task 3: Add color (20 points)
Modify your scatterplot to color the points by vehicle class (class).
- The legend should appear automatically
- Give the legend a clear title (hint: use
labs())
Task 4: Create faceted plots (20 points)
Create the same scatterplot (displacement vs highway mpg, colored by class), but now faceted by drive type (drv).
- Use
facet_wrap() - Each panel should be clearly labeled
Task 5: Save your plot (15 points)
Save your final faceted plot as a PNG file.
ggsave("mpg_faceted_plot.png", width = 10, height = 6)Verify the file was created in your project folder.
Task 6: Reflection (10 points)
At the bottom of your script, answer these questions in comments:
# Reflection Questions:
# 1. What relationship do you observe between engine size and fuel efficiency?
# 2. Do all vehicle classes follow the same pattern?
# 3. What was the most challenging part of this assignment?Submission Checklist
Before submitting, make sure:
Submit your .R file on Canvas.
Grading Rubric
| Task | Points |
|---|---|
| Task 1: Data exploration | 10 |
| Task 2: Basic scatterplot | 15 |
| Task 3: Color mapping | 20 |
| Task 4: Faceting | 20 |
| Task 5: Saving plot | 15 |
| Task 6: Reflection | 10 |
| Code runs without errors | 10 |
| Total | 100 |