FreesearchR/R/theme.R

114 lines
3.1 KiB
R
Raw Permalink Normal View History

2024-12-18 10:37:37 +01:00
#' Custom theme based on unity
#'
#' @param ... everything passed on to bslib::bs_theme()
#'
#' @returns theme list
#' @export
2024-12-19 11:32:32 +01:00
custom_theme <- function(...,
version = 5,
2025-04-24 13:16:33 +02:00
primary = FreesearchR_colors("primary"),
secondary = FreesearchR_colors("secondary"),
2025-01-16 12:23:39 +01:00
bootswatch = "united",
base_font = bslib::font_google("Montserrat"),
heading_font = bslib::font_google("Public Sans", wght = "700"),
2025-04-24 13:16:33 +02:00
code_font = bslib::font_google("Open Sans"),
success = FreesearchR_colors("success"),
info = FreesearchR_colors("info"),
warning = FreesearchR_colors("warning"),
danger = FreesearchR_colors("danger")
2024-12-19 11:32:32 +01:00
# fg = "#000",
# bg="#fff",
# base_font = bslib::font_google("Alice"),
# heading_font = bslib::font_google("Jost", wght = "800"),
# heading_font = bslib::font_google("Noto Serif"),
# heading_font = bslib::font_google("Alice"),
) {
2024-12-18 10:37:37 +01:00
bslib::bs_theme(
...,
"navbar-bg" = primary,
2024-12-19 11:32:32 +01:00
version = version,
primary = primary,
secondary = secondary,
bootswatch = bootswatch,
base_font = base_font,
heading_font = heading_font,
2025-04-24 13:16:33 +02:00
code_font = code_font,
success=success,
info=info,
warning=warning,
danger=danger
2024-12-18 10:37:37 +01:00
)
}
2025-01-30 14:32:11 +01:00
2025-04-24 13:16:33 +02:00
FreesearchR_colors <- function(choose = NULL) {
out <- c(
primary = "#1E4A8F",
secondary = "#FF6F61",
success = "#00C896",
warning = "#FFB100",
danger = "#CC2E25",
2025-04-24 13:16:33 +02:00
extra = "#8A4FFF",
info = "#11A0EC",
bg = "#FFFFFF",
dark = "#2D2D42",
fg = "#000000"
)
2025-04-24 13:16:33 +02:00
if (!is.null(choose)) {
2025-04-30 13:03:20 +02:00
unname(out[choose])
2025-04-24 13:16:33 +02:00
} else {
out
}
}
#' Use the FreesearchR colors
#'
#' @param n number of colors
#'
#' @returns character vector
#' @export
#'
#' @examples
#' FreesearchR_palette(n=7)
FreesearchR_palette <- function(n){
rep_len(FreesearchR_colors(),n)
}
2025-01-30 14:32:11 +01:00
2025-04-24 13:16:33 +02:00
2025-01-30 14:32:11 +01:00
#' GGplot default theme for plotting in Shiny
#'
#' @param data ggplot object
#'
#' @returns ggplot object
#' @export
#'
gg_theme_shiny <- function() {
ggplot2::theme(
axis.title = ggplot2::element_text(size = 18),
axis.text = ggplot2::element_text(size = 14),
strip.text = ggplot2::element_text(size = 14),
legend.title = ggplot2::element_text(size = 18),
legend.text = ggplot2::element_text(size = 14),
plot.title = ggplot2::element_text(size = 24),
plot.subtitle = ggplot2::element_text(size = 18)
)
2025-01-30 14:32:11 +01:00
}
#' GGplot default theme for plotting export objects
#'
#' @param data ggplot object
#'
#' @returns ggplot object
#' @export
#'
gg_theme_export <- function() {
ggplot2::theme(
axis.title = ggplot2::element_text(size = 18),
axis.text.x = ggplot2::element_text(size = 14),
legend.title = ggplot2::element_text(size = 18),
legend.text = ggplot2::element_text(size = 14),
plot.title = ggplot2::element_text(size = 24)
)
2025-01-30 14:32:11 +01:00
}