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:

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)

We can create a plot with default font sizes as follows:

plot(x, y,                                        # Default plot
     main = "My Title", sub = "My Subtitle")

 

base r plot default font size

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)

 

base r plot font size of labels

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)

 

base r plot font size of axes

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)

 

base r plot font size of title

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)

 

base r plot font size of subtitle

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)

 

base r plot font size of all text

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.

 

The YouTube video will be added soon.

 

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.

 



Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top