GGPlot Title, Subtitle And Caption : The Ultimate Guide - Datanovia
Maybe your like
This article describes how to add and change a main title, a subtitle and a caption to a graph generated using the ggplot2 R package. We’ll show also how to center the title position, as well as, how to change the title font size and color.
In this R graphics tutorial, you will learn how to:
- Add titles and subtitles by using either the function ggtitle() or labs().
- Add caption to a ggplot and change the position.
- Split a long title into two lines or more using \n as a text separator.
- Change the font appearance (text size, color and face) of titles and caption. For example, to set a bold ggplot title, use this: p + theme(plot.title = element_text(face = "bold")). The allowed values for the font face include: “plain”, “italic”, “bold” and “bold.italic”.
- Change title position to the center or to any other locations (left, right). The default ggplot title alignment is not centered. It is on the left. It’s possible to put the title in the middle of the chart by specifying the argument hjust = 0.5 in the function element_text(): p + theme(plot.title = element_text(hjust = 0.5)). The options hjust = 1 and hjust = 0 place titles on the right and the left side of the plot, respectively.
Contents:
- Key ggplot2 R functions
- Add main title, subtitle and caption
- Change title and caption style: font size, color and face
- Center the title position
- Change caption position
- Conclusion
Key ggplot2 R functions
- Start by creating a box plot using the ToothGrowth data set:
- Add titles using one of the following functions:
- p + ggtitle(“Main title”, subtitle = “My subtitle”)
- p + labs(title = “Main title”, subtitle = “My subtitle”, caption = “My caption”)
- Key ggplot2 theme options to change the font of titles and captions:
Arguments of the function element_text() includes:
- color, size, face, family: to change the text font color, size, face (“plain”, “italic”, “bold”, “bold.italic”) and family.
- lineheight: change space between two lines of text elements. Number between 0 and 1. Useful for multi-line plot titles.
- hjust and vjust: number in [0, 1], for horizontal and vertical adjustment of titles, respectively.
- hjust = 0.5: Center the plot titles.
- hjust = 1: Place the plot title on the right
- hjust = 0: Place the plot title on the left
Add main title, subtitle and caption
- Use the function labs()


- Alternatively, you can use the function ggtitle() as follow:
If the title is too long, you can split it into two or multiple lines using \n. In this case you can adjust the space between text lines by specifying the argument lineheight in the theme function element_text():
p + labs(title = "Effect of Vitamin C on Tooth Growth \n in Guinea Pigs")+ theme(plot.title = element_text(lineheight = 0.9))
Change title and caption style: font size, color and face
- Key functions: theme() and element_text(color, size, face)
- Allowed values for font face: “plain”, “italic”, “bold” and “bold.italic”

Center the title position
Specify the argument hjust = 0.5 in the function element_text() to put the title in the middle:
p + theme( plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5) )
Other locations adjustment for titles include:
- hjust = 1: Place the title on the right
- hjust = 0: Place the title on the left
Change caption position
As for titles, you can modify the caption position using hjust. For example to place the caption on the plot left side, type this:
p + theme( plot.caption = element_text(hjust = 0) )
Conclusion
- Create an example of ggplot:
- Add titles, subtitles and captions:
Tag » How To Center Ggplot Title
-
Center Plot Title In Ggplot2 - Stack Overflow
-
How To Center Plot Title/subtitle In Ggplot2
-
Change Position Of Ggplot Title In R (4 Examples) - Statistics Globe
-
How To Change Title Position In Ggplot2 (With Examples) - Statology
-
Centre Ggplot Title And Subtitle - Gists · GitHub
-
How To Center Plot Title In Ggplot2 With R - The Research Scientist Pod
-
How To Center Ggplot Plot Title - Anycodings
-
R - How To Align The Plot Title To The Center In Ggplot - DiscoverBits
-
How To Center Ggplot Titles R - YouTube
-
How To Change Position Of Ggplot Title In R ? - GeeksforGeeks
-
Center Align Ggplot Title When Title Is Placed Within The Plot Area
-
Centre The Title Of Ggplot - RStudio Community
-
How To Center Align A KM Plot Title In R? - RStudio Community
-
Change Position Of Ggplot2 Plot Title (Examples) | Adjust & Move To ...