The “theme_minimal” Function in R
Package: ggplot2
Purpose: To apply a minimalistic theme to ggplot objects, removing unnecessary elements.
General Class: Theme
Required Argument(s): None
Notable Optional Arguments:
base_size: The base font size for the plot.
base_family: The base font family for the plot.
base_line_size: The base line size for elements like axis lines.
base_rect_size: The base size for elements like rectangles.
base_rect_rel_size: The base size relative to the overall height of the plot for elements like rectangles.
base_rect_hjust: The base horizontal justification for elements like rectangles.
Example:
# Example usage
library(ggplot2)
# Run this code for special fonts using a Windows device.
# After the functions are run once, the extrafont...
# package only needs to be libraried for subsequent use.
library(extrafont)
font_import()
loadfonts(device = "win")
# Create a data frame
my_data <- data.frame(
x_values = seq(1, 10),
y_values = rnorm(10)
)
# Create a ggplot object with a minimalistic theme, remove base_family if Arial is unavailable.
my_plot <- ggplot(data = my_data, aes(x = x_values, y = y_values)) +
geom_point() +
theme_minimal(base_size = 14, base_family = "Arial", base_line_size = 1)
# Print the plot
print(my_plot)In this example, the theme_minimal function from the ggplot2 package is used to apply a minimalistic theme to a ggplot. The optional arguments allow for customization of font size (base_size), font family (base_family), line size (base_line_size), and other visual elements. This function is part of the extensive theming options provided by ggplot2 for creating visually appealing and customized plots.