Change Font of Plot in R
In this article, we will be looking at the two different approaches to change the font of the plot in R programming language.
Method 1: Using windowsFont() function and family argument
In this approach to change the font of the given plot, the user needs to call the windowsFont() which is one of the in-build function of the R programming language, with the name of the font as its parameter, this function is used to specify the font family as per requirement and with this, the user also need to use the family argument of the plot() function to change the font family of the texts of the plot in the R programming language.
windowsFont() function is used to handle the translation of a device-independent R graphics font family name to a Windows font description and is available only on Windows.
- family: a character vector containing the font family name (“TT” as the first two characters indicate a TrueType font).
Method 2: Using windowsFont() and theme() function from ggplot2
In this method to change the font of the given plot user firstly needs to install and import the ggplot2 package and then call the windowsFont() function to specify the required parameter as its parameter and secondly need to call the theme() function from the ggplot2 package to change the font of the given ggplot2 plot.
theme() function used to modify theme settings.
theme(…, complete = FALSE, validate = TRUE)
- …: a list of element names, element pairings that modify the existing theme.
- complete: set this to TRUE if this is a complete theme, such as the one returned by theme_grey().
- validate: TRUE to run validate_element, FALSE to bypass checks.