geom_density: Draw a density plot

View source: R/geom_density.R

geom_densityR Documentation

Draw a density plot

Description

geom_density is a geom that should be used in conjunction with ggplot to draw a density plot. Compare to histograms or area plots.

Usage

ggplot(data, aes(x = var)) +
  geom_density()

Arguments

data

A tibble to be used for the density plot

var

Specify which variable should be drawn on the x-axis.

Examples

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)

cobriant/qelp documentation built on July 1, 2022, 7:24 a.m.