How to Add Title to a GGPlot

How to Add Title to a GGPlot

This tutorial shows how to add title to a ggplot. The function labs() is used.

Related Book

GGPlot2 Essentials for Great Data Visualization in R


Load required packages and set the theme function theme_minimal() as the default theme:

library(ggplot2) # For data visualization

Add title, subtitle and caption

# Default plot
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) + 

# Add titles
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
              subtitle = "Plot of length by dose",
              caption = "Data source: ToothGrowth")

Version: Français

No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments