Marginal and conditional histograms
Now, turn your attention to a new variable: horsepwr
. The goal is to get a sense of the marginal distribution of this variable and then compare it to the distribution of horsepower conditional on the price of the car being less than $25,000.
You'll be making two plots using the "data pipeline" paradigm, where you start with the raw data and end with the plot.
Cet exercice fait partie du cours
Exploratory Data Analysis in R
Instructions
- Create a histogram of the distribution of
horsepwr
across all cars and add an appropriate title. Start by piping in the raw dataset. - Create a second histogram of the distribution of horsepower, but only for those
cars that have an
msrp
less than $25,000. Keep the limits of the x-axis so that they're similar to that of the first plot, and add a descriptive title.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create hist of horsepwr
cars %>%
ggplot(aes(___)) +
___ +
ggtitle(___)
# Create hist of horsepwr for affordable cars
cars %>%
filter(___) %>%
ggplot(aes(___)) +
___ +
xlim(c(90, 550)) +
ggtitle(___)