Site icon R-bloggers

Changing the Font Size in Base R Plots

[This article was first published on Data Science Tutorials, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Changing the Font Size in Base R Plots appeared first on Data Science Tutorials

What do you have to lose?. Check out Data Science tutorials here Data Science Tutorials.

Changing the Font Size in Base R Plots, To alter the 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  size of title
     cex.sub=2, #change  size of subtitle
     cex.lab=2, #change  size of axis labels
     cex.axis=2) #change  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 sizes.

plot(df$x, df$y, main='Title', sub='Subtitle')

Example 1: Change Font Size of Title

The story title’s size can be altered using the code below:

build a scatterplot with the title’s 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’ size can be altered using the code below:

generate a scatterplot with axis labels in larger 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 size can be altered using the code below:

generate a scatterplot with the axis text’s size raised.

plot(df$x, df$y, main='Title', sub='Subtitle', cex.axis=2)

Check your inbox or spam folder to confirm your subscription.

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)

The post Changing the Font Size in Base R Plots appeared first on Data Science Tutorials

Learn how to expert in the Data Science field with Data Science Tutorials.

To leave a comment for the author, please follow the link and comment on their blog: Data Science Tutorials.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.