Written and maintained by CASRAI Editorial Board
Last updated
In ggplot2 the plot title and the legend title are set in different places, and that is why most “ggplot titles” questions come down to one choice: labs() for the text, theme() for how it looks. The plot title is labs(title = "...") (or ggtitle("...")); the legend title is labs() with the name of the aesthetic the legend belongs to, for example labs(colour = "Cylinders"). This guide covers both, plus subtitle, caption, styling, position and removal, using the current ggplot2 reference pages.
What titles are used for in research plots
A figure in a paper or report usually needs a title that says what is plotted, a legend title that names the grouping variable with its units or meaning (not the raw column name), and often a caption for the data source. ggplot2 gives each of these its own label slot, so they can be set together in one labs() call. For the matching axis labels see axis titles and labels in R.
Install or access (official source only)
ggplot2 is an R package distributed through CRAN and is free to use. Install it once and load it in each session:
install.packages("ggplot2")
library(ggplot2)
The official reference for every function used below is the ggplot2 reference site.
Step-by-step: set the plot title, subtitle and legend title
1. Set the plot title and subtitle
Add labs() to the plot. The reference page for labs() lists title, subtitle, caption and tag as arguments, and gives this form in its own examples:
p + labs(title = "New plot title", subtitle = "A subtitle")
The subtitle is displayed below the title. ggtitle(label, subtitle = waiver()) is documented on the same page as the shortcut for the same job, so p + ggtitle("New plot title") and p + labs(title = "New plot title") are both correct.
2. Add a caption or a tag
By default the caption is displayed in the bottom-right of the plot and the tag at the top-left. The reference examples are p + labs(caption = "(based on data from ...)") and p + labs(title = "title", tag = "A").
3. Change the legend title (ggplot legend title)
The legend title is attached to an aesthetic, not to the word “legend”. The labs() documentation says the name of each extra argument “should be an aesthetic”, and gives p + labs(colour = "Cylinders") as the example. Use the aesthetic that actually produces the legend: colour (or color), fill, shape, size and so on.
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
geom_point() +
labs(title = "Fuel economy by weight", colour = "Cylinders")
When a plot has several legends, set one label per aesthetic in the same call, for example labs(colour = "Cylinders", shape = "Gear"). A fixed colour scale has its own naming rules, covered in ggplot colour scales.
4. Set the legend title from the scale or the guide
Axis and legend labels can also be set in the scale. The labs() page says setting them there is recommended when you are changing other scale options at the same time, for instance scale_colour_manual(name = "Cylinders", values = ...). The legend itself is also a guide: guide_legend() takes a title argument, “a character string or expression indicating a title of guide”, so guides(colour = guide_legend(title = "Cylinders")) sets the same text at the guide level.
5. Style and position the titles
Text and appearance are separate. labs() only changes the words; the look is controlled in theme() with element_text():
plot.titleandplot.subtitle: appearance of the title and subtitle; the title is left-aligned by default.legend.title: appearance of the legend title. It inherits from the generaltitleelement, so a change totitlereaches the plot title, axis titles and legend titles together.plot.title.position:"panel"(the default) aligns titles and caption to the plot panels;"plot"aligns them to the entire plot.legend.title.position: where the legend title sits relative to the main legend:"top","right","bottom"or"left".
p + theme(
plot.title = element_text(face = "bold"),
plot.title.position = "plot",
legend.title = element_text(face = "italic"),
legend.title.position = "top"
)
The guide_legend() page adds that the guide’s own theme argument partially overrides, and is combined with, the plot’s theme, so a legend can be styled for one guide only. Wider theme controls are in ggplot2 themes.
6. Remove a title
To remove a label, set it to NULL, as in p + labs(subtitle = NULL). For the legend title on one guide, guide_legend(title = NULL) hides it: “If NULL, the title is not shown.”
Output and how to read it
The rendered plot shows the title at the top (left-aligned to the panel unless you move it), the subtitle beneath it, the caption bottom-right and the tag top-left. Each legend shows its title above its keys by default unless legend.title.position moves it. A label you never set falls back to the default derived from the mapping, so a legend titled factor(cyl) means no label was supplied for that aesthetic. Examples of full plots are in scatterplots in R and bar plots in R.
Troubleshooting
The legend title did not change
Check the aesthetic name. labs() matches labels by aesthetic, so labs(fill = "Group") has no effect on a legend that is built from colour. Match the argument to the aesthetic in your aes() call.
The title is not aligned with the left edge of the figure
By default titles align to the plot panel. Set theme(plot.title.position = "plot") to align them to the whole plot.
I want the legend title above, beside or below the keys
Use theme(legend.title.position = "top") (or "right", "bottom", "left"), or pass the theme inside guide_legend() to affect one legend.
A scale and labs() both name the same legend
Pick one place per aesthetic and keep it there. The documentation recommends the scale when you are already changing other scale options, which keeps the name next to the other settings.
Free alternatives: ways to set the same title
ggplot2 itself is free, and it offers several equivalent routes to the same titles. Which to use depends on what else you are changing.
| What you want | Call | Note from the ggplot2 reference |
|---|---|---|
| Plot title | labs(title = "...") or ggtitle("...") |
Both are documented; ggtitle() also takes a subtitle. |
| Legend title, quick | labs(colour = "...") |
Argument name must be an aesthetic. |
| Legend title with other scale options | scale_colour_manual(name = "...") |
Recommended when changing other scale options. |
| Legend title on one guide | guides(colour = guide_legend(title = "...")) |
title = NULL hides it. |
| Title appearance | theme(plot.title = element_text(...)), theme(legend.title = element_text(...)) |
Both inherit from title. |
FAQ
How do I add a title to a ggplot?
Add labs(title = "Your title") or ggtitle("Your title") to the plot with +.
How do I change the legend title in ggplot2?
Use labs() with the aesthetic that creates the legend, for example labs(colour = "Cylinders") or labs(fill = "Group"). You can also set name in the scale or title in guide_legend().
What is the difference between ggtitle() and labs(title = )?
Both set the plot title. ggtitle(label, subtitle) is the shorter form for title and subtitle; labs() can also set the caption, tag and every aesthetic label in one call.
How do I remove the legend title?
Use guides(colour = guide_legend(title = NULL)) for the relevant aesthetic. Setting a label to NULL in labs() removes that label.
How do I move the legend title?
Set legend.title.position in theme() to "top", "right", "bottom" or "left".
Sources (official docs)
- ggplot2 reference,
labs()andggtitle(): https://ggplot2.tidyverse.org/reference/labs.html (checked 2026-10-29) - ggplot2 reference,
guide_legend(): https://ggplot2.tidyverse.org/reference/guide_legend.html (checked 2026-10-29) - ggplot2 reference,
theme(): https://ggplot2.tidyverse.org/reference/theme.html (checked 2026-10-29)







