How to put the title inside the plot using ggplot2 in R? Last Updated : 08 Nov, 2022 Comments Improve Suggest changes Like Article Like Report A title to a plot gives information about the graph so that it is easier for the reader to interpret what relations the variables are supposed to depict. This article discusses how we can put a title inside a plot and further discusses various ways in which the title can be formatted. The examples are given below use bar plot. To add title within a plot ggtitle() function is used. Syntax: ggtitle("Title For Plot") Later to add this title to the plot we simply have to set margins. Approach Specify the data object. it has to be a data frame, and it needs one numeric and one categorical variable.Call ggplot2() function and put first parameter 'data' and then set the aesthetics function 'aes()'.Inside aes() function, set the categorical variable for the X axis, use the numeric for the Y axis.Call geom_bar() with ggtitle().Add marginsDisplay plot Example 1: 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")+ theme(plot.title=element_text(margin=margin(t=40,b=-30))) Output: Customization of Title of plot using ggplot2 It is a common need to set the title in several lines. To add a break in the title, simply write '\n' in the text. If you want to bold or highlight some word(s) then just use expression() function. This section depicts how the title inserted can be formatted accordingly. Example 1: R library(ggplot2) data <- data.frame( name=c("A","B","C","D","E") , value=c(3,12,5,18,45) ) # For Add Some Several Lines ggplot(data, aes(x=name, y=value)) + geom_bar(stat = "identity", fill = "green")+ ggtitle("New Line Title \n For Barplot") + theme_minimal() # For Highlight Some Word Or Words my_title <- expression(paste("This is barplot with ", bold("Bold Title"))) ggplot(data, aes(x=name, y=value)) + geom_bar(stat = "identity", fill = "green")+ ggtitle(my_title) + theme(plot.title=element_text(margin=margin(t=40,b=-30))) Output: Now let's modify our title appearance and position by theme() Function with plot.title parameter. The Appearance can be adjusted with family, face, color, or size. When position can be changed using hjust & vjust. Example 2: R library(ggplot2) data <- data.frame( name=c("A","B","C","D","E") , value=c(3,12,5,18,45) ) # Customise Title Appearance ggplot(data, aes(x=name, y=value)) + geom_bar(stat = "identity", fill = "green")+ ggtitle("A Green & Bold Title") + theme_minimal() + theme( plot.title=element_text(family='', face='bold', colour='green', size=26, margin=margin(t=40,b=-30)) ) . Output: Example 3: R library(ggplot2) data <- data.frame( name=c("A","B","C","D","E") , value=c(3,12,5,18,45) ) # Change Position of Title ggplot(data, aes(x=name, y=value)) + geom_bar(stat = "identity", fill = "green")+ ggtitle("Plot with right sided Title") + theme_minimal() + theme( plot.title=element_text( hjust=1, vjust=0.5, face='bold', margin=margin(t=40,b=-30)) ) Output: Comment More infoAdvertise with us Next Article How to put the title inside the plot using ggplot2 in R? E erkrutikpatel Follow Improve Article Tags : R Language R-ggplot Similar Reads How to Plot a Zoom of the Plot Inside the Same Plot Area Using ggplot2 in R When working with data visualization, it can be useful to highlight a particular portion of a plot by zooming in on a specific region. This is often referred to as an inset plot. In R, using the ggplot2 package, you can overlay a zoomed-in section of your plot within the same plot area to provide mo 3 min read How to save a plot using ggplot2 in R? In this article, we are going to see how to save GGPlot in R Programming language. ggplot2 is a plotting package in R that is used to create complex plots from data specified in a data frame. It provides a more programmatic interface for specifying which variables to plot on to the graphical device, 3 min read How to plot means inside boxplot using ggplot2 in R? In this article, we are going to see how to plot means inside boxplot using ggplot in R programming language. A box plot in base R is used to summarise the distribution of a continuous variable. It can also be used to display the mean of each group. Means or medians can also be computed using a box 4 min read How to put text on different lines to ggplot2 plot in R? ggplot2 is a plotting package in R programming language that is used to create complex plots from data specified in a data frame. It provides a more programmatic interface for specifying which variables to plot onto the graphical device, how they are displayed, and general visual properties. In thi 3 min read How to change legend title in R using ggplot ? A legend helps understand what the different plots on the same graph indicate. They basically provide labels or names for useful data depicted by graphs. In this article, we will discuss how legend names can be changed in R Programming Language. Let us first see what legend title appears by default. 2 min read Like