A good graph is always introduced by a title that tells the reader what the figure is about. It does not need to be long or detailed. Often it only states which variables are represented, or it summarizes the purpose of the graph.

A few examples:

Here we will see a simple way to set up a title above the graph as illustrated with the scatter plot below. This plot is the result by the following code and is stored in the object baseplot so that we can reuse it throughout the whole tutorial:

baseplot <- ggplot(df, aes(values1, values2)) +
  geom_point(size=2) 
baseplot



Adding plot title, subtitle and tag

A simple way to add a title to the plot is to use the function labs():

baseplot +
  labs(title="values2 vs. values1")



As you may see above, the title appears by default at the top left corner, just above the plot. This is not directly modifiable with the function labs(). In fact, labs() does not allow you to do much more than displaying a title (with title =), a subtitle just under the title (with subtitle =) and a tag in the top left corner of the whole figure (with tag =):

baseplot +
  labs(title = "values2 vs. values1", subtitle = "presented in the form of a scatterplot", tag="Fig.1A")



Tuning the look of the title

In order to modify the look of the title that has been added by labs(), you will have to modify the theme. To do so, you will have to add an additional line to the code and use the function theme(plot.title = element_text()). Using this line and a few additional arguments, you will be able to set the position (with hjust = and vjust =), color (with color =), size (with size =), font (with family =), etc:

baseplot +
  labs(title="values2 vs. values1") +
  theme(plot.title = element_text(family = "serif", 
                                  face = "bold", 
                                  color = "blue",
                                  size = 18,
                                  hjust = .5,
                                  vjust = 2))