geom_area: Draw an area plot

View source: R/geom_area.R

geom_areaR Documentation

Draw an area plot

Description

geom_area is a geom that should be used in conjunction with ggplot to draw an area plot.

Usage

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

Arguments

data

A tibble to be used for the area plot

var

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

Examples

library(tidyverse)
library(gapminder)

# Visualize the distribution of a variable (compare to
# geom_histogram)

ggplot(gapminder, aes(x = lifeExp)) +
  geom_area(stat = "bin")

# Visualize the distribution of a variable by group:

ggplot(gapminder, aes(x = lifeExp, fill = continent)) +
  geom_area(stat = "bin")

# Adjust the previous plot so that groups overlap ("dodge")
# instead of stack:

ggplot(gapminder, aes(x = lifeExp, fill = continent)) +
  geom_area(stat = "bin", pos = "dodge")

# Increase the transparency (alpha) of the area plot
# so that overlapped information is visible:

ggplot(gapminder, aes(x = lifeExp, fill = continent)) +
  geom_area(stat = "bin", pos = "dodge", alpha = .6)


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