Drawing density plots using geom_density()
Another alternative to histograms are the density plots. Those are usually seen as a visual more related to the academic environment; accurate interpretations are only obtained by being familiar to the statistical concept of densities. On the other hand shallow interpretations can be easily grasped by anyone.
For an instance let's go back to the Iris data set in order to plot the petal's length kernel density estimates discriminated by species. This can be done using ggplot2
, ggvis
and plotly
. Until the fist half of 2017 plotly
would require computation to be directly done before actually plotting. This recipe is about to demonstrate it all.
How to do it...
Upcoming steps are demonstrating how to breed density plots using ggplot2
, ggvis
and plotly
.
- To craft a density plot using
ggplot2
stack the functiongeom_density()
:
> library(ggplot2) > gg2_petal <- ggplot(data = iris, aes(x = Petal.Length, ...