# How to change the title size of a graph using ggplot2 in R?

R ProgrammingServer Side ProgrammingProgramming

The size of a graph title mattes a lot for the visibility because it is the first thing people look at after plot area. Its size must not be very large nor very small but is should be different from the axis titles and axes labels so that there exists a clarity in the graph. This can be done by using theme function.

## Example

Consider the below data frame −

set.seed(1)
x <-rnorm(100)
df <-data.frame(x)
library(ggplot2)

Creating histogram of x and writing title of the graph −

ggplot(df,aes(x))+geom_histogram(binwidth=0.5)+ggtitle("Histogram")

## Output

Changing the size of the title

ggplot(df,aes(x))+geom_histogram(binwidth=0.5)+ggtitle("Histogram")+theme(plot.title = element_text(size=20))

## Output

Published on 24-Aug-2020 15:30:09