4.8 Data, aesthetics mappings and layers: Exercise 1
- See the three ggplot2 statements below. Please describe the data, aesthetic mappings and layers used for each of the following plots (Wickham 2016, 14).
- You’ll need to guess a little because you haven’t seen all the datasets and functions yet, but use your common sense! See if you can predict what the plot will look like before running the code.
ggplot(mpg, aes(cty, hwy)) + geom_point()
ggplot(diamonds, aes(carat, price)) + geom_point()
ggplot(economics, aes(date, unemploy)) + geom_line()
ggplot(mpg, aes(cty)) + geom_histogram()
- The fact that we can guess the outcome from the code attests to its readability!
- Lesson: Choose readable variable names (e.g.,
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer.