Skip to content

Commit

Permalink
theme_grey is terrible
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 18, 2024
1 parent 814cd35 commit 5ce414c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
7 changes: 7 additions & 0 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 41 additions & 2 deletions R/tinytheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(...)
Expand Down Expand Up @@ -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)
)
3 changes: 2 additions & 1 deletion R/tpar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}
Expand All @@ -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...
Expand Down

0 comments on commit 5ce414c

Please sign in to comment.