| geom_area | R Documentation |
geom_area is a geom that should be used in conjunction
with ggplot to draw an area plot.
ggplot(data, aes(x = var)) + geom_area()
data |
A tibble to be used for the area plot |
var |
Specify which variable should be drawn on the x-axis. |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.