“How can I use bold font in R? Can you provide some examples?” 2

“How can I use bold font in R? Can you provide some examples?”

In R, bold font can be used by using the “bold” function or by using the “font.bold” argument in the “plot” function. This will make the specified text appear in a bold format. For example, “plot(x, y, font.bold = TRUE)”. Additionally, the “bold” function can be used within a “text” function to make specific text bold, such as “text(x, y, labels = bold(“This is bold text”))”. These methods can be used to add emphasis or highlight important information in graphs or visualizations created in R.

Use Bold Font in R (With Examples)


You can use the following basic syntax to produce bold font in R plots:

substitute(paste(bold('this text is bold')))

The following examples show how to use this syntax in practice.

Example 1: Bold Font on Axis Labels of Plot

The following code shows how to create a scatter plot in R using normal font for both axis labels:

#define data
x <- c(1, 2, 3, 4, 4, 5, 6, 6, 7, 9)
y <- c(8, 8, 9, 10, 13, 12, 10, 11, 14, 17)

#create scatter plot with normal font for axis labels
plot(x, y, xlab='X Label', ylab='Y Label')

And the following code shows how to specify bold font for the x-axis and y-axis labels of a plot:

#define data
x <- c(1, 2, 3, 4, 4, 5, 6, 6, 7, 9)
y <- c(8, 8, 9, 10, 13, 12, 10, 11, 14, 17)

#create scatterplot with axes labels in bold
plot(x, y, xlab = substitute(paste(bold('X Label'))),
           ylab = substitute(paste(bold('Y Label'))))

Notice how the labels for both axes are now bold.

Example 2: Bold Font with Text in Plot

The following code shows how to include bold font for a text element inside of a plot:

#define data
x <- c(1, 2, 3, 4, 4, 5, 6, 6, 7, 9)
y <- c(8, 8, 9, 10, 13, 12, 10, 11, 14, 17)

#create scatterplot
plot(x, y)

#add normal text at location x=3, y=14
text(3, 14, 'This is some normal text')

#add bold text at location x=3, y=16 
text(3, 16, substitute(paste(bold('This is some bold text'))))

Notice the difference between the bold font and the normal font.

Additional Resources

Cite this article

stats writer (2024). “How can I use bold font in R? Can you provide some examples?”. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-bold-font-in-r-can-you-provide-some-examples/

stats writer. "“How can I use bold font in R? Can you provide some examples?”." PSYCHOLOGICAL SCALES, 28 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-bold-font-in-r-can-you-provide-some-examples/.

stats writer. "“How can I use bold font in R? Can you provide some examples?”." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-bold-font-in-r-can-you-provide-some-examples/.

stats writer (2024) '“How can I use bold font in R? Can you provide some examples?”', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-bold-font-in-r-can-you-provide-some-examples/.

[1] stats writer, "“How can I use bold font in R? Can you provide some examples?”," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. “How can I use bold font in R? Can you provide some examples?”. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top