library(tidyverse)Classwork 10
Distribution of a Numeric Variable
Complete the questions and submit your responses on the corresponding Brightspace page.
Fill each ____ with the appropriate variable, function, argument, or value, then run your completed code in an R script. Keep your code and brief written interpretations together. This page contains everything you need to start; no earlier classwork is required.
Setup and data
The built-in mpg data contains 234 vehicle model configurations from model years 1999 and 2008. Each row represents a configuration, not an individual driver or purchase. The variable cty records city fuel economy in miles per gallon: higher values mean a vehicle travels farther using one gallon of fuel. Dataset reference: ggplot2 · mpg.
1. Make two histograms
Make a histogram of city fuel economy with a bin width of 1 mpg. Then make a second version with a bin width of 5 mpg.
ggplot(data = mpg,
mapping = aes(x = cty)) +
geom_____(____)
ggplot(data = ____,
mapping = aes(x = ____)) +
____(____)2. Read the plot instructions and axes
Identify the data, the variable mapped to x, and the geometric object used in your first plot (name its geom_*() function). What does its vertical axis count? Explain why no variable is mapped to y aesthetic: what does ggplot calculate from the observations?
3. Compare the bin widths
Describe one detail that the narrower bins show more clearly, or one pattern that the wider bins make easier to see.
4. Describe the peaks
Are bar heights roughly uniform, or do you see one clear peak (unimodal) or two clear peaks (bimodal)? Does changing the bin width change your description? Small bumps alone need not indicate separate groups.
5. Describe the tails
Is the longer tail toward smaller values (left-skewed) or larger values (right-skewed), or are the tails roughly balanced? Identify the tail from the values along the horizontal axis, rather than from the side with the tallest bars.
A histogram can have both a peak-count description and a skew description. For example, one clear peak and a longer right tail means unimodal and right-skewed.
