Scatterplots
This lesson is called Scatterplots, part of the Fundamentals of R course. This lesson is called Scatterplots, part of the Fundamentals of R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Loading transcript...
View code shown in video
# Load Packages -----------------------------------------------------------
library(tidyverse)
# Import Data -------------------------------------------------------------
penguins <- read_csv("penguins.csv")
# Scatterplots ------------------------------------------------------------
# We use geom_point() to make a scatterplot.
ggplot(
data = penguins,
mapping = aes(
x = bill_length_mm,
y = bill_depth_mm
)
) +
geom_point()
Your Turn
# Load Packages -----------------------------------------------------------
library(tidyverse)
# Import Data -------------------------------------------------------------
penguins <- read_csv("penguins.csv")
# Scatterplots ------------------------------------------------------------
# Make a scatterplot that shows flipper length on the x axis and body mass on the y axis.
# YOUR CODE HERE
Learn More
Claus Wilke talks about scatterplots in Chapter 12 of his book Fundamentals of Data Visualization. Michael Toth also has a long blog post about all of the ins and outs of making scatterplots in ggplot.
You can also find examples of code to make scatterplots on the Data to Viz website , the R Graph Gallery website , and in Chapter 5 of the R Graphics Cookbook.
Have any questions? Put them below and we will help you out!
Course Content
33 Lessons
1
The Grammar of Graphics
04:36
2
Scatterplots
03:40
3
Histograms
04:51
4
Bar Charts
04:53
5
Setting color and fill Aesthetic Properties
02:43
6
Setting color and fill Scales
05:12
7
Setting x and y Scales
02:58
8
Adding Text to Plots
05:50
9
Plot Labels
02:59
10
Themes
02:10
11
Facets
02:56
12
Save Plots
02:49
13
Bring it All Together (Data Visualization)
06:14
You need to be signed-in to comment on this post. Login.
Lilly Yu • October 7, 2026
In the Your Turn solution, I noticed that the way each line break/indentation is different than the way it was presented in the video (which seems to be the default indentation when you hit the enter key/line break). Is there a reason the solution is different? Is one preferable over the other? How do we get the line breaks/indentations in the solution?
Gracielle Higino Coach • October 8, 2026
Hi Lilly! We'll talk a bit about it in the live session today. It has to do with automatic styling with Air (in this case). Not having line breaks does not make your code wrong. Indentation is important only in specific cases (we'll talk about them in the Quarto lessons). Overall we like line breaks and indentation because it makes it easier to read!