labs: Modify ggplot labels

View source: R/labs.R

labsR Documentation

Modify ggplot labels

Description

Use a labs() layer to add a title and subtitle to the ggplot, modify x or y axis labels, and/or modify the legend label.

Usage

+ labs(title, subtitle, x, y, color, ...)

Arguments

title

A title for the ggplot. It's good practice to state the main findings of the plot ("Life Expectancy Increases Over Time") instead of just re-stating the names of the variables on each axis.

subtitle

If needed, you can specify a subtitle.

x

Rename the label on the x-axis.

y

Rename the label on the y-axis.

color

Rename the label on the legend for color (or fill, size, etc.)

Examples

library(tidyverse)
library(gapminder)

# Add a title to a ggplot:

gapminder %>%
  ggplot(aes(x = year, y = lifeExp, color = continent)) +
  geom_line(stat = "summary", fun = median) +
  labs(title = "Life Expectancy Increases Over Time")

# Also rename the y-axis from lifeExp to Median Life Expectancy:

gapminder %>%
  ggplot(aes(x = year, y = lifeExp, color = continent)) +
  geom_line(stat = "summary", fun = median) +
  labs(
    title = "Life Expectancy Increases Over Time",
    y = "Median Life Expectancy"
  )


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