geom_line: Draw a line plot

View source: R/geom_line.R

geom_lineR Documentation

Draw a line plot

Description

geom_line is a geom that should be used in conjunction with ggplot to draw a line plot. Lines connect observations and are ordered by the variable on the x-axis.

Usage

ggplot(data, aes(x, y, color)) +
  geom_line()

Arguments

data

A tibble to be used for the line plot

x

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

y

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

color

Specify which variable (if any) should be represented by line color.

Examples

library(tidyverse)
library(gapminder)

# Draw a line plot to visualize how life expectancy
# in a country increased over time:

gapminder %>%
  filter(country == "Netherlands") %>%
  ggplot(aes(x = year, y = lifeExp)) +
  geom_line()

# Draw a line plot to visualize how life expectancy
# in multiple countries increased over time:

gapminder %>%
  filter(continent == "Oceania") %>%
  ggplot(aes(x = year, y = lifeExp, color = country)) +
  geom_line()

# Draw a line plot to visualize how median life expectancy
# in the world increased over time:

gapminder %>%
  ggplot(aes(x = year, y = lifeExp)) +
  geom_line(stat = "summary", fun = median)

# Draw a line plot to visualize how median life expectancy
# in each continent increased over time:

gapminder %>%
  ggplot(aes(x = year, y = lifeExp, color = continent)) +
  geom_line(stat = "summary", fun = median)


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