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:
Syntax
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
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")
Login to try C/C++/Java/PHP code in the editor
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
- Writing
xlab = Timewithout quotes, when labels must be strings. - Using
color = "blue"instead ofcol = "blue", which is ignored or errors. - Adding
title()beforeplot(), when it must come after a plot exists.
Chapter Summary
plot(),hist(),barplot(),boxplot(), andpie()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: