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 done.
Use of this function is a powerful way to customize the non-data components of your plots: i.e. titles, labels, fonts, background, gridlines, and legends. This function can also be used to give plots a consistent customized look.
theme (line, text, axis.title,axis.text)
- line: all line elements (element_line())
- text: all text elements (element_text())
- axis.title: labels of axes (element_text()). Specify all axes’ labels (axis.title)
- axis.text: tick labels along axes (element_text()). Specify all axis tick labels (axis.text)
To change text size and angle, theme() is called with axis.text set to appropriate values, this attribute as the name suggests acts upon axis text. To this element_text() function is called with its attribute- size and angle, set to a required value.
theme(axis.text = element_text(size, angle) )