Base R Graphics Fonts
Here is a basic example of how to change fonts in base R graphics. In base R, you can set the font family using the family argument in text functions.
plot(1:10, main="Main Title", sub="Subtitle", xlab="X-axis Label", ylab="Y-axis Label", family="serif")
text(5, 5, "Sample Text", family="serif")
Output:
- plot(1:10, …): Creates a basic scatter plot of the numbers 1 through 10.
- main, sub, xlab, ylab: Add a main title, subtitle, and labels for the x and y axes.
- family=”serif”: Sets the font family for the text elements to a serif font.
- text(5, 5, “Sample Text”, family=”serif”): Adds the text “Sample Text” at the coordinates (5, 5) using a serif font.
A simple scatter plot with customized font properties (e.g., main title in blue, subtitle in red, etc.).
Fonts In R
In data visualization and data representation, it becomes very important how we express our words and code with the help of different fonts. The text plays a very crucial role in conveying useful information and enhancing the aesthetic part of the plot. R Programming Language, being a powerful open-source programming language provides various fonts which can help to build visually appealing and professional-looking plots that are very useful to convey the message.