Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Data Into Insights (Spring 2021)/R4DS Chapter 3 Exercises
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
There are a lot of exercises in R4DS. For [https://r4ds.had.co.nz/data-visualisation.html Chapter 3], these are the ones that we will go over in class. You should create a new R Markdown file (<code>File > New File > R Markdown</code>) for this and future R assignments. This will give you a new example R Markdown file. You can delete everything after ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` and replace it with your own answers. As a reminder, you can just write text in the main part of the document. To create code chunks you push <code>Insert > R</code> or type <code>Ctrl + Alt + I</code> (<code>Cmd + Option + I</code> on Mac). 3.2 2. How many rows are in mpg? How many columns? 3. What does the drv variable describe? Read the help for ?mpg to find out. 4. Make a scatterplot of hwy vs cyl. 5. What happens if you make a scatterplot of class vs drv? Why is the plot not useful? 3.3 1. What’s gone wrong with this code? Why are the points not blue? 2. Which variables in mpg are categorical? Which variables are continuous? (Hint: type ?mpg to read the documentation for the dataset). How can you see this information when you run mpg? 3. Map a continuous variable to color, size, and shape. How do these aesthetics behave differently for categorical vs. continuous variables? 4. What happens if you map the same variable to multiple aesthetics? 5. What does the stroke aesthetic do? What shapes does it work with? (Hint: use ?geom_point) 6. What happens if you map an aesthetic to something other than a variable name, like aes(colour = displ < 5)? Note, you’ll also need to specify x and y. 3.5 2. What do the empty cells in plot with facet_grid(drv ~ cyl) mean? How do they relate to this plot? 3. What plots does the following code make? What does . do? 4. What are the advantages to using faceting instead of the colour aesthetic? What are the disadvantages? How might the balance change if you had a larger dataset? 3.6 1. What geom would you use to draw a line chart? A boxplot? A histogram? An area chart? 4. What does the se argument to geom_smooth() do? 6. Recreate the R code necessary to generate the following graphs. I am leaving out 3.7+ for this week. I still suggest that you read these sections, but focus for now on really understanding the basics of creating plots and use these sections for future reference.
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information