Ungraded practice problem. Not an actual assignment if you are taking course for credit.
Practice Problem 1 |
| 1-2 hrs |
This assignment provides you with practice in R and data exploration. Use the built-in data sets mtcars and mpg in R to answer the questions below using only the R Console (or, optionally, R Studio). Be sure to clearly label each question in your script, e.g., ## Question 1
Question 1 (5 Points)
What does the "gear" column variable describe? To find out, read the help page using ?mtcars. Add your answer as comments (using #) to your script.
Question 2 (5 Points)
Create a scatterplot of mpg (x axis) vs cyl (y axis) for the mtcars data set. What does the scatterplot tell you? Add your answer as comments (using #) to your script.
Question 3 (10 Points)
Which variables in mtcars are categorical? Which variables are continuous? (Hint: type ?mtcars to read the documentation for the dataset). How can you see this information when you display mtcars in R?
Question 4 (10 Points)
Type in and execute the following code and explain in a comment what the . in the code stands for and when you would use it.
Question 5 (10 Points)
Read ?facet_wrap. What does nrow do? What does ncol do? What other options control the layout of the individual panels? Why doesn't facet_grid() have nrow and ncol arguments? Explain your answer in comments. It's important to learn how to read definitions and descriptions of functions.
Question 6 (10 Points)
Review the code below and predict what the output will look like. Then, run the code in R and check your predictions. Does the code run? If you don't believe so, why not? What error do you get? How do you interpret error messages?
Question 7 (10 Points)
What is the default geom associated with stat_summary()? How could you rewrite the plot below to use that geom function instead of the stat function? This post may provide some hints.
Question 8 (10 Points)
What does the plot code below tell you about the relationship between cty and hwy in the built-in dataset mpg? Why is coord_fixed() important? What does geom_abline() do? Provide your answers in comments in your R script.
Question 9 (30 Points)
Work through all the examples (excluding those from exercises) within Chapter 3 in our text book, R for Data Science. Add the code to your R script file and add appropriate comments describing each code snippet. Make sure they all work correctly - note anything that doesn't work.
Hints
- If you get errors with ggplot, you may need to install the extrafont package. Here's some sample code:
Code Editor