_defaults.R
library(ggplot2)
library(ggdark)
library(showtext)
library(colorspace)
library(ggthemes)
library(gt)
# get plot fonts
font_add_google(name = "Public Sans", family = "Public Sans")
showtext_auto()
# Set global variable for setting fonts
# that aren't set by theme(text=...)
<- "Public Sans"
PLOT_FONT
# from the theme _variables.scss
<- "#222222"
body_bg <- darken("#375a7f", 0.50)
plot_bg <- lighten(
major
plot_bg,amount = 0.25
)<- lighten(
minor
plot_bg,amount = 0.125
)<- lighten(plot_bg, 0.5)
strip_bg
<- "#EE6677"
ptol_red <- "#4477AA"
ptol_blue
theme_set(theme_minimal(base_size = 16) +
theme(text = element_text(family = "Public Sans"),
plot.background = element_rect(fill = "white", colour = NA),
panel.background = element_rect(fill = "white", colour = NA),
panel.grid = element_blank(),
legend.key = element_blank(),
#strip.background = element_rect(fill = strip_bg),
#strip.text = element_text(color = "white"),
axis.ticks = element_blank(),
axis.line = element_line(color = "grey60", linewidth = 0.2),
legend.background = element_blank()))
<- function(){
theme_dark theme(
#panel.border = element_blank(),
text = element_text(family = "Public Sans", colour = "white"),
axis.text = element_text(colour = "white"),
rect = element_rect(colour = "#222", fill = "#222"),
plot.background = element_rect(fill = "#222", colour = NA),
panel.background = element_rect(fill = "#424952"),
strip.background = element_rect(fill="#3d3d3d"),
strip.text = element_text(color = "white")
)
}
<- function(){
theme_no_y theme(
axis.text.y = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.y = element_blank()
)
}
<- function(){
theme_no_x theme(
axis.text.x = element_blank(),
axis.title.x = element_blank(),
panel.grid.major.x = element_blank()
)
}
= function(out.width, out.width.default = 0.7, fig.width.default = 6) {
out2fig * out.width / out.width.default
fig.width.default
}
options(
ggplot2.discrete.colour = lapply(1:12, ggthemes::ptol_pal()),
ggplot2.discrete.fill = lapply(1:12, ggthemes::ptol_pal()),
ggplot2.ordinal.colour = \(...) scale_color_viridis_d(option = "G", direction = -1, ...),
ggplot2.ordinal.fill = \(...) scale_fill_viridis_d(option = "G", direction = -1, ...),
ggplot2.continuous.colour = \(...) scico::scale_color_scico(palette = "batlow", ...),
ggplot2.continuous.fill = \(...) scico::scale_fill_scico(palette = "batlow", ...)
)
# set a crop: true hook
::knit_hooks$set(crop = knitr::hook_pdfcrop)
knitr
# dark gt theme
<- function(tbl){
dark_gt_theme
<- list(
style_cells cells_body(),
cells_column_labels(),
cells_column_spanners(),
cells_footnotes(),
cells_row_groups(),
cells_source_notes(),
cells_stub(),
cells_stubhead(),
cells_title()
)
<- tbl$`_summary` |>
summary_info map(
~":GRAND_SUMMARY:" %in% .x$groups
|>
) list_simplify()
if(any(summary_info)){
<- c(
style_cells
style_cells,list(
cells_grand_summary(),
cells_stub_grand_summary()
)
)
}
if(any(!(summary_info %||% T))){
<- c(
style_cells
style_cells,list(
cells_stub_summary(),
cells_summary()
)
)
}
|>
tbl opt_table_font(
font = c(
google_font(name = "Public Sans"),
default_fonts()
)|>
)tab_style(
style = "
background-color: var(--bs-body-bg);
color: var(--bs-body-color)
",
locations = style_cells
) }
Reuse
CC-BY-SA 4.0