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


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

Updated on: 24-Aug-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements