← Back to R Course | Chapter 10: Data Visualization | Lesson 7 of 7

Adding Labels and Titles

Labels and titles tell readers what a plot is about, like writing a caption and naming the axes. R lets you add a main title and words along each side.

In this page:

  1. Adding Labels and Titles
Syntax
r
plot(x, y, main = "title", xlab = "x label", ylab = "y label", col = "color")

Adding Labels and Titles

Plot functions accept main for a title, xlab/ylab for axis labels, and col for color, all directly as arguments.

Clear labeling turns a raw plot into something a reader can actually interpret without guessing what the axes represent. Well-labeled plots are a basic requirement for any chart meant to be shared or published.

Note: Always set main, xlab, and ylab -- an unlabeled plot is nearly useless to anyone besides the person who made it.

Example: Adding Labels and Titles

markup
x <- 1:5
y <- c(2, 4, 6, 8, 10)

cat("plot(x, y, main='Growth', xlab='Time', ylab='Value', col='blue')\n")
cat("would draw a labeled scatter plot titled 'Growth'\n")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Writing xlab = Time without quotes, when labels must be strings.
  2. Using color = "blue" instead of col = "blue", which is ignored or errors.
  3. Adding title() before plot(), when it must come after a plot exists.
Chapter Summary
  • plot(), hist(), barplot(), boxplot(), and pie() create different chart types.
  • par() settings control how graphics are arranged and drawn.
  • Labels and titles make charts clear.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.