Increase Font Size in Base R Plot (5 Examples)
In this article you’ll learn how to increase font sizes in a plot in the R programming language.
The page contains these contents:
- Creation of Example Data
- Example 1: Increase Font Size of Labels
- Example 2: Increase Font Size of Axes
- Example 3: Increase Font Size of Main Title
- Example 4: Increase Font Size of Subtitle
- Example 5: Increase Font Size of All Text
- Video & Further Resources
Here’s how to do it:
Creation of Example Data
In the examples of this tutorial, I’ll use the following data:
set.seed(7531) # Create random data x <- rnorm(100) y <- x + rnorm(100) |
set.seed(7531) # Create random data x <- rnorm(100) y <- x + rnorm(100)
We can create a plot with default font sizes as follows:
plot(x, y, # Default plot main = "My Title", sub = "My Subtitle") |
plot(x, y, # Default plot main = "My Title", sub = "My Subtitle")
Figure 1: Base R Plot with Default Font Sizes.
Now, if we want to increase certain font sizes, we can use the cex arguments of the plot function. Have a look at the following examples…
Example 1: Increase Font Size of Labels
We can increase the labels of our plot axes with the cex.lab argument:
plot(x, y, # Increase label size main = "My Title", sub = "My Subtitle", cex.lab = 3) |
plot(x, y, # Increase label size main = "My Title", sub = "My Subtitle", cex.lab = 3)
Figure 2: Base R Plot with Increased Font Size of Labels.
Example 2: Increase Font Size of Axes
The axis text can be increased with the cex.axis argument:
plot(x, y, # Increase axis size main = "My Title", sub = "My Subtitle", cex.axis = 3) |
plot(x, y, # Increase axis size main = "My Title", sub = "My Subtitle", cex.axis = 3)
Figure 3: Base R Plot with Increased Font Size of Axes.
Example 3: Increase Font Size of Main Title
The font size of the main title can be increased with the cex.main argument:
plot(x, y, # Increase title size main = "My Title", sub = "My Subtitle", cex.main = 3) |
plot(x, y, # Increase title size main = "My Title", sub = "My Subtitle", cex.main = 3)
Figure 4: Base R Plot with Increased Font Size of Main Title.
Example 4: Increase Font Size of Subtitle
The font size of the subtitle is getting larger by specifying a larger value for the cex.sub argument:
plot(x, y, # Increase subtitle size main = "My Title", sub = "My Subtitle", cex.sub = 3) |
plot(x, y, # Increase subtitle size main = "My Title", sub = "My Subtitle", cex.sub = 3)
Figure 5: Base R Plot with Increased Font Size of Subtitle.
Example 5: Increase Font Size of All Text
And finally, if we want to increase all font sizes of all plot elements, we can apply all cex arguments simultaneously:
plot(x, y, # Increase all text sizes main = "My Title", sub = "My Subtitle", cex.lab = 3, cex.axis = 3, cex.main = 3, cex.sub = 3) |
plot(x, y, # Increase all text sizes main = "My Title", sub = "My Subtitle", cex.lab = 3, cex.axis = 3, cex.main = 3, cex.sub = 3)
Figure 6: Base R Plot with Increased Font Size of All Text Elements.
Note that I always specified the cex arguments to be equal to 3. You may change this value to whatever value you want. The larger the cex value gets, the larger is the font size. You may also decrease the font size.
Video & Further Resources
I have recently published a video on my YouTube channel, which shows the contents of this article. You can find the video below.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Furthermore, I can recommend to read some of the other tutorials on my homepage:
Summary: This tutorial illustrated how to adjust text sizes in a plot in R programming. Don’t hesitate to let me know in the comments, if you have additional questions. Furthermore, don’t forget to subscribe to my email newsletter for regular updates on the newest tutorials.
Subscribe to my free statistics newsletter: