geom_density | R Documentation |
geom_density
is a geom that should be used in conjunction
with ggplot
to draw a density plot. Compare to histograms or area plots.
ggplot(data, aes(x = var)) + geom_density()
data |
A tibble to be used for the density plot |
var |
Specify which variable should be drawn on the x-axis. |
library(tidyverse) library(gapminder) # Draw a basic density plot: ggplot(gapminder, aes(x = lifeExp)) + geom_density() # Compare different groups using color and fill: gapminder %>% ggplot(aes(x = lifeExp, color = continent, fill = continent)) + geom_density() # Adjust transparency (alpha): gapminder %>% ggplot(aes(x = lifeExp, color = continent, fill = continent)) + geom_density(alpha = .3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.