Skip to Content
R Programming Fundamentals
book

R Programming Fundamentals

by Kaelen Medeiros
September 2018
Beginner
206 pages
4h 27m
English
Packt Publishing
Content preview from R Programming Fundamentals

Creating a Scatterplot of Two Continuous Variables

Let's now create scatterplots using geom_point() and geom_().

  1. Create a scatterplot of the bodywt and sleep_total variables from msleep:
ggplot(msleep, aes(bodywt, sleep_total)) + geom_point()
  1. This scatterplot is a great candidate for using geom_jitter(), as many of the sleep_total observations cluster around the zero bodyweight. We'll use a fairly large width for jitter to really separate these points, because the scale of bodywt is in the thousands:
ggplot(msleep, aes(bodywt, sleep_total)) + geom_jitter(width = 50)

Output: The following is the output we get when we execute the code mentioned in Step 1:

The following is the output we get when we execute the code mentioned in Step 2

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Programming Fundamentals

R Programming Fundamentals

Samik Sen, Marcin Dubel
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781789612998Supplemental Content