ggplot2 – Title and Subtitle with Different Size and Color in R
Last Updated :
16 May, 2021
A Title and the subtitle to a plot give a piece of information about the graph that what the graph actually wants to represent. This article describes how to add a Title and Subtitle with Different Sizes and Colors using ggplot2 in R Programming.
To add a Title and Subtitle within a plot, first, we have to import ggplot2 library using library() function. If you have not installed yet, you can simply install it by writing a command install.packages(“ggplot2”) in R Console.
library(ggplot2)
Consider the following data for the example:
data <- data.frame(
name=c("A","B","C","D","E") ,
value=c(3,12,5,18,45)
)
|
Name |
Value |
1 |
A |
3 |
2 |
B |
12 |
3 |
C |
5 |
4 |
D |
18 |
5 |
E |
45 |
Creating a Plot using ggplot() function with the value of X-axis as Name and Y-axis as Value and make it a barplot using geom_bar() function of the ggplot2 library. Here we use the fill parameter to geom_bar() function to color the bars of the plots.
R
library (ggplot2)
data <- data.frame (
Name= c ( "A" , "B" , "C" , "D" , "E" ) ,
Value= c (3, 12, 5, 18, 45)
)
ggplot (data, aes (x = Name, y = Value)) +
geom_bar (stat = "identity" , fill = "green" )
|
Output:

Adding Title and Subtitle To R Plot
Method 1. By Using ggtitle() function:
For this, we simply add ggtitle() function to a geom_bar() function. Inside ggtitle() function, we can directly write the title that we want to add to the plot without defining any parameter but for add Subtitle to the plot using ggtitle() function, we have to use subtitle parameter to ggtitle() function and then assign the subtitle to that parameter.
Syntax : ggtitle(“Title of the Plot”, subtitle = “Subtitle of the Plot”)
Parameter :
- we give title that we want to add, as it’s parameter.
- subtitle is used as a second parameter of ggtitle() function to add subtitle of plot.
Below is the implementation:
R
library (ggplot2)
data <- data.frame (
Name= c ( "A" , "B" , "C" , "D" , "E" ),
Value= c (3, 12, 5, 18, 45)
)
ggplot (data, aes (x = Name, y = Value)) +
geom_bar (stat = "identity" , fill = "green" )+
ggtitle ( "Title For Barplot" ,
subtitle = "This is Subtitle"
)
|
Output:

Method 2. By Using labs() Function:
To add Title and Subtitle to R Plot using labs() function, things are same as above only difference is we use labs() function instead of ggtitle() function and assign title that we want to add to the parameter called ‘title’. Subtitle can be added using the same parameter of the above example. Output is also the same as the above example output.
Syntax : ggtitle(“Title of the Plot”, subtitle = “Subtitle of the Plot”)
Parameter :
- title is used as a first parameter to add the title of Plot.
- subtitle is used as a second parameter to add the subtitle of Plot.
Below is the implementation:
R
library (ggplot2)
data <- data.frame (
Name = c ( "A" , "B" , "C" , "D" , "E" ) ,
Value = c (3, 12, 5, 18, 45)
)
ggplot (data, aes (x = Name, y = Value)) +
geom_bar (stat = "identity" , fill = "green" )+
labs (title = "Title For Barplot" ,
subtitle = "This is Subtitle"
)
|
Output:

Title and Subtitle With Different Size
To change the size of the title and subtitle, we add the theme() function to labs() or ggtitle() function, whatever you used. Here we use labs() function. Inside theme() function, we use plot.title parameter for doing changes in the title of plot and plot.subtitle for doing changes in Subtitle of Plot. We use element_text() function as a value of plot.title and plot.subtitle parameter. We can change the appearance of texts using element_text() function. To change the size of the title and subtitle, we use the size parameter of element_text() function. Here we set the size of the title as 30 and the size of the subtitle as 20.
Below is the implementation:
R
library (ggplot2)
data <- data.frame (
Name = c ( "A" , "B" , "C" , "D" , "E" ) ,
Value= c (3, 12, 5, 18, 45)
)
ggplot (data, aes (x = Name, y = Value)) +
geom_bar (stat = "identity" , fill = "green" )+
labs (title = "Title For Barplot" ,
subtitle = "This is Subtitle"
)+
theme (plot.title = element_text (size = 30),
plot.subtitle = element_text (size = 20)
)
|
Output:

Title and Subtitle with Different size
Title and Subtitle With Different Color
To change the color of Title and Subtitle, We simply add a color parameter to element_text() function. All others are the same as the above implementation. Here we set the value of the color of title as green and the value of subtitle as red.
R
library (ggplot2)
data <- data.frame (
Name = c ( "A" , "B" , "C" , "D" , "E" ) ,
Value = c (3, 12, 5, 18, 45)
)
ggplot (data, aes (x = Name, y = Value)) +
geom_bar (stat = "identity" , fill = "green" )+
labs (title = "Title For Barplot" ,
subtitle = "This is Subtitle"
)+
theme (plot.title = element_text (size = 30, color = "green" ),
plot.subtitle = element_text (size = 20, color = "red" )
)
|
Output:

Title and Subtitle with Different Color
Similar Reads
Multiple Density Plots and Coloring by Variable with ggplot2 in R
In this article, we will discuss how to make multiple density plots with coloring by variable in R Programming Language. To make multiple density plots with coloring by variable in R with ggplot2, we first make a data frame with values and categories. Then we draw the ggplot2 density plot using the
3 min read
Align Plot with Different Axes Vertically Using Cowplot in R
When working with data visualization in R, you often encounter scenarios where you need to align multiple plots vertically, even if they have different axis scales or dimensions. The cowplot package is particularly useful for combining and aligning such plots seamlessly. This article provides a deta
4 min read
Draw ggplot2 plot with two Y-axes on each side and different scales in R
There are many data available that have more than one unit like Temperature, Pressure, Height of a person, etc. We want to represent these data using more than one unit in a basic plot because other users may not be familiarized with the unit you have provided in the plot. It becomes difficult for t
3 min read
Changing Font Size and Direction of Axes Text in ggplot2 in R
In this article, we will discuss how to change the font size and the direction of the axis text using the ggplot2 plot in R Programming language. For both of the requirement theme() function is employed. After plotting a regular graph, simply adding theme() with appropriate values will get the job d
2 min read
Use different colors/shapes for scatterplot with two groups in R
In this article, we will be looking to the different approaches to colors/shapes for scatterplots with two groups in R programming language. The plot in R can be used for visual analysis of the data. The ggplot2 library in R is used to create data visualizations. The package can be downloaded and in
6 min read
Change the Outline Color for Histogram Bars Using ggplot2 in R
In data visualization, customizing the appearance of a plot can greatly enhance its readability and presentation. One common customization when working with histograms is changing the outline color of the bars. By default, ggplot2 may not always add outlines, but you can easily modify this behavior
4 min read
geom_area plot with areas and outlines in ggplot2 in R
An Area Plot helps us to visualize the variation in quantitative quantity with respect to some other quantity. It is simply a line chart where the area under the plot is colored/shaded. It is best used to study the trends of variation over a period of time, where we want to analyze the value of one
3 min read
Combine and Modify ggplot2 Legends with Ribbons and Lines
The ggplot2 library is often used for data visualization. One feature of ggplot2 is the ability to create and modify legends for plots. In this tutorial, we will cover how to combine and modify ggplot2 legends with ribbons and lines. To begin, make sure you have the ggplot2 library installed and loa
4 min read
Add Bold and Italic text to ggplot2 Plot in R
In this article, we will discuss how to add Bold and Italic Text to a plot using ggplot2 in the R Programming language. To add the bold and italic text we will be using the annotate() function from the ggplot2 library in R language, this function helps to add the text to the graph with different var
3 min read
Adding Legend to Multiple Line Plots with ggplot in R
In this article, we are going to see how can we add a legend to multiple line plots with ggplot in the R programming language. For a plot that contains more than one line plot, a legend is created by default if the col attribute is used. All the changes made in the appearance of the line plots will
2 min read