Rewrite of theme_reach()
This commit is contained in:
parent
f45d9e44ba
commit
045e277cb6
1 changed files with 126 additions and 92 deletions
|
|
@ -1,35 +1,70 @@
|
|||
#' @title Base REACH ggplot2 theme
|
||||
#' @title ggplot2 theme with REACH color palettes
|
||||
#'
|
||||
#' @param family The font family. Default to "Leelawadee"
|
||||
#' @param palette Palette name from 'pal_reach()'.
|
||||
#' @param discrete Boolean indicating whether color aesthetic is discrete or not
|
||||
#' @param reverse Boolean indicating whether the palette should be reversed
|
||||
#' @param family The font family for all plot's texts. Default to "Leelawadee".
|
||||
#' @param text_size The size of all text other than the title, subtitle and caption. Defaults to 10.
|
||||
#' @param title_size The size of the title text_family. Defaults to 14.
|
||||
#' @param plot_background_pal The color for the plot background color. Default to white.
|
||||
#' @param panel_background_pal The color for the panel background color. Default to white.
|
||||
#' @param legend_position Position of the legend; Default to "right". Can take "right", "left", "top", "bottom" or "none".
|
||||
#' @param legend_direction Direction of the legend. Default to "vertical". Can take "vertical" or "horizontal".
|
||||
#' @param void Boolean to remove all elements from the plot. Default to FALSE.
|
||||
#' @param ... Additional arguments passed to `ggblanket::gg_theme()`.
|
||||
#'
|
||||
#' @description Give some reach colors and fonts to a ggplot. Based on theme_bw()
|
||||
#'
|
||||
#' @description Give some reach colors and fonts to a ggplot.
|
||||
#'
|
||||
#' @return The base REACH theme
|
||||
#'
|
||||
#' @export
|
||||
theme_reach <- function(family = "Leelawadee") {
|
||||
theme_reach <- function(
|
||||
palette = "main",
|
||||
discrete = TRUE,
|
||||
reverse = FALSE,
|
||||
family = "Leelawadee",
|
||||
text_size = 10,
|
||||
title_size = 14,
|
||||
plot_background_pal = "#FFFFFF",
|
||||
panel_background_pal = "#FFFFFF",
|
||||
void = FALSE,
|
||||
legend_position = "right",
|
||||
legend_direction = "vertical",
|
||||
...
|
||||
) {
|
||||
|
||||
rlang::check_installed("ggplot2", reason = "Package \"ggplot2\" needed for `theme_reach_*()` to work. Please install it.")
|
||||
# Basic simple theme
|
||||
theme_reach <- ggblanket::gg_theme(
|
||||
text_family = family,
|
||||
text_size = text_size,
|
||||
title_size = title_size,
|
||||
plot_background_pal = plot_background_pal,
|
||||
panel_background_pal = panel_background_pal,
|
||||
void = void
|
||||
)
|
||||
|
||||
ggplot2::theme_bw() +
|
||||
ggplot2::theme(
|
||||
title = ggplot2::element_text(family = family,
|
||||
size = 12,
|
||||
colour = "#58585A",
|
||||
hjust = 0.5,
|
||||
vjust = 0.5),
|
||||
text = ggplot2::element_text(family = family,
|
||||
colour = "#58585A"),
|
||||
axis.title = ggplot2::element_text(size = 11),
|
||||
axis.text = ggplot2::element_text(size = 10),
|
||||
legend.text = ggplot2::element_text(size = 11),
|
||||
strip.text = ggplot2::element_text(size = 11),
|
||||
legend.title = ggplot2::element_text(size = 11)
|
||||
|
||||
# Default legend to right position
|
||||
theme_reach <- theme_reach +
|
||||
ggplot2::theme(legend.position = legend_position)
|
||||
|
||||
# Defaut legend to vertical direction
|
||||
theme_reach <- theme_reach +
|
||||
ggplot2::theme(legend.direction = legend_direction)
|
||||
|
||||
# Add reach color palettes by default
|
||||
theme_reach <- list(
|
||||
theme_reach,
|
||||
scale_color(palette = palette, discrete = discrete, reverse = reverse),
|
||||
scale_fill(palette = palette, discrete = discrete, reverse = reverse)
|
||||
)
|
||||
|
||||
|
||||
return(theme_reach)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#' @title Some REACH theme for ggplot
|
||||
#'
|
||||
#' @param family The font family. Default to "Leelawadee"
|
||||
|
|
@ -49,7 +84,6 @@ theme_reach_borders <- function(family = "Leelawadee") {
|
|||
|
||||
|
||||
#' @title Some reach more minimal theme for a ggplot histogram
|
||||
#'
|
||||
#' @param family The font family. Default to "Leelawadee"
|
||||
#'
|
||||
#' @description Give some REACH colors and fonts to a ggplot. Based on theme_bw(). To be used for vertical bar charts.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue