2.4 Histograms and Density Plots

Construct a histogram of the weight (carat) of each diamond in the "diamonds" dataset.

ggplot(diamonds, aes(x=carat)) + geom_histogram()


Construct a histogram of the weight (carat) of each diamond, but set the binwidth to .5.

ggplot(diamonds, aes(x=carat)) + geom_histogram(binwidth=.5)


Construct a density plot of the weight (carat) of each diamond

ggplot(diamonds, aes(x=carat)) + geom_density()


Construct a density plot of the weight (carat) of each diamond, showing a separate density for each "clarity" rating

ggplot(diamonds, aes(x=carat, color=clarity)) + geom_density()