From 5ce414ca577312ea2360b8bcd7b57d55d54c23ca Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 17 Nov 2024 22:06:33 -0500 Subject: [PATCH] theme_grey is terrible --- R/facet.R | 7 +++++++ R/tinytheme.R | 43 +++++++++++++++++++++++++++++++++++++++++-- R/tpar.R | 3 ++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/R/facet.R b/R/facet.R index 3f4e1c8c..183189d8 100644 --- a/R/facet.R +++ b/R/facet.R @@ -121,6 +121,13 @@ get_facet_fml = function(formula, data = NULL) { draw_facet_window = function(grid, ...) { list2env(list(...), environment()) + # draw background color only in the grid rectangle + grid.bg = get_tpar("grid.bg") + if (!is.null(grid.bg)) { + corners = par("usr") + rect(corners[1], corners[3], corners[2], corners[4], col = grid.bg, border = NA) + } + if (isFALSE(add)) { ## optionally allow to modify the style of axis interval calculation if (!is.null(xaxs)) par(xaxs = xaxs) diff --git a/R/tinytheme.R b/R/tinytheme.R index 8ea032cc..45497d61 100644 --- a/R/tinytheme.R +++ b/R/tinytheme.R @@ -7,6 +7,7 @@ #' @param theme A character string specifying the name of the theme to apply. #' If `NULL`, the current theme is reset to default settings. Available themes include: #' - `"simple"` +#' - `"ipsum"` #' @param action "append", "prepend", or "replace" to the hook. #' @param ... Named arguments to override specific theme settings. These arguments are #' passed to `tpar()` and take precedence over the predefined settings in the selected @@ -44,10 +45,11 @@ tinytheme = function(theme = NULL, ..., action = "replace") { return(invisible(NULL)) } - assert_choice(theme, c("simple", "ipsum")) + assert_choice(theme, c("simple", "ipsum", "grey")) settings = switch(theme, "simple" = theme_simple, - "ipsum" = theme_ipsum + "ipsum" = theme_ipsum, + "grey" = theme_grey ) dots = list(...) @@ -104,3 +106,40 @@ theme_ipsum = list( side.sub = 3, tck = 0 # Tick mark length (0 = none) ) + + +theme_grey = list( + adj.main = 0.5, # Center main title + adj.sub = 0.5, # Center subtitle + adj.xlab = 0.5, # Center x-axis title + adj.ylab = 0.5, # Center y-axis title + bg = "white", # Background color + bty = "n", # No box around the plot + cex = 1, # Base font size scaling + cex.axis = 0.8, # Axis text size + cex.lab = 1, # Axis label size + cex.main = 1.2, # Main title size + cex.sub = 0.9, # Subtitle size + col.axis = "#4D4D4D", # Axis text color + col.lab = "black", # Axis label color + col.main = "black", # Main title color + col.sub = "black", # Subtitle color + col.ticks = "#B3B3B3", # Tick color + col.xaxs = NA, # No color for x-axis line + col.yaxs = NA, # No color for y-axis line + fg = "black", # Foreground color (text, lines) + font = 1, # Font style (plain) + font.axis = 1, # Font style for axis labels + font.lab = 1, # Font style for axis titles + font.main = 1, # Font style for the main title + font.sub = 1, # Font style for the subtitle + grid = TRUE, # Display grid + grid.col = "white", # Grid line color + grid.lwd = 1, # Grid line width + grid.lty = "solid", # Grid line type + grid.bg = "#EBEBEB", + las = 1, # Horizontal axis labels + family = "", # Base font family + mgp = c(3, 1, 0), # Margin for axis titles (mgp[1]), axis labels (mgp[2]), axis lines (mgp[3]) + tck = -0.02 # Tick mark length (negative for inside ticks) +) diff --git a/R/tpar.R b/R/tpar.R index a106bfcc..0a204113 100644 --- a/R/tpar.R +++ b/R/tpar.R @@ -189,7 +189,7 @@ tpar = function(...) { tinyplot_params = c( "adj.main", "adj.sub", "adj.ylab", "adj.xlab", "col.xaxs", "col.yaxs", "col.axis", "lmar", "ribbon.alpha", "grid.lwd", "grid.lty", "grid.col", "grid", "file.res", - "file.height", "file.width", "facet.font", "facet.cex", "side.sub") + "file.height", "file.width", "facet.font", "facet.cex", "side.sub", "grid.bg") for (n in intersect(names(opts), tinyplot_params)) { .tpar[[n]] = opts[[n]] } @@ -207,6 +207,7 @@ tpar = function(...) { assert_numeric(.tpar[["facet.font"]], len = 1, null.ok = TRUE, name = "facet.font") assert_numeric(.tpar[["facet.cex"]], len = 1, null.ok = TRUE, name = "facet.cex") assert_numeric(.tpar[["side.sub"]], len = 1, null.ok = TRUE, name = "side.sub") + assert_string(.tpar[["grid.bg"]], null.ok = TRUE, name = "grid.bg") ## Like par(), we want the return object to be dependent on inputs...