Drawing histograms
Recall that histograms cut up a continuous variable into discrete bins and, by default, maps the internally calculated count
variable (the number of observations in each bin) onto the y aesthetic. An internal variable called density
can be accessed by using the ..
notation, i.e. ..density..
. Plotting this variable will show the relative frequency, which is the height times the width of each bin.
This exercise is part of the course
Introduction to Data Visualization with ggplot2
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Plot mpg
___ +
# Add a histogram layer
___