Changing the Font Size in Base R Plots
Changing the Font Size in Base R Plots, To alter the font size of different elements in base R charts, use the syntax shown below:
plot(df$x, df$y, main='Title', sub='Subtitle', cex.main=2, #change font size of title cex.sub=2, #change font size of subtitle cex.lab=2, #change font size of axis labels cex.axis=2) #change font size of axis text
The scatterplot shown below in base R can be used with this syntax by using the examples that follow:
Make a data frame
df <- data.frame(x=c(1, 2, 3, 4, 5, 6), y=c(54, 81, 22, 36, 45, 63)) df
x y 1 1 54 2 2 81 3 3 22 4 4 36 5 5 45 6 6 63
Create a scatterplot using the standard font sizes.
plot(df$x, df$y, main='Title', sub='Subtitle')
Example 1: Change Font Size of Title
The story title’s font size can be altered using the code below:
build a scatterplot with the title’s font size raised
plot(df$x, df$y, main='Title', sub='Subtitle', cex.main=2)
Example 2: Change Font Size of Subtitle
The plot’s subtitle can be changed by using the code provided below:
generate a scatterplot with the subtitle’s text size raised
plot(df$x, df$y, main='Title', sub='Subtitle', cex.sub=2)
Example 3: Change Font Size of Axis Labels
The plot’s axis labels’ font size can be altered using the code below:
generate a scatterplot with axis labels in larger font sizes.
plot(df$x, df$y, main='Title', sub='Subtitle', cex.lab=2)
Example 4: Change Font Size of Axis Text
The plot’s axis text’s font size can be altered using the code below:
generate a scatterplot with the axis text’s font size raised.
plot(df$x, df$y, main='Title', sub='Subtitle', cex.axis=2)
Further Resources:-
The following tutorials provide guidance on using R:
How to Add a caption to ggplot2 Plots in R? (datasciencetut.com)
How to Label Outliers in Boxplots in ggplot2? (datasciencetut.com)
How to add labels at the end of each line in ggplot2? (datasciencetut.com)