| Title: | BFH Theme and Color Palettes for ggplot2 |
|---|---|
| Description: | Provides comprehensive theming support for ggplot2 graphics following Bispebjerg og Frederiksberg Hospital and Region Hovedstaden visual identity guidelines. Includes color palettes for both Hospital and Region H branding, themes, scale functions, and helper utilities for creating consistent and professional visualizations. Uses modern 'systemfonts' package for robust font detection with graceful fallback. Recommends 'ragg', 'svglite', and Cairo devices for high-quality output. |
| Authors: | Johan Reventlow [aut, cre] |
| Maintainer: | Johan Reventlow <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.2 |
| Built: | 2026-06-04 14:14:50 UTC |
| Source: | https://github.com/johanreventlow/BFHtheme |
Places the BFH mark logo at a fixed, brand-compliant position on ggplot2 visualizations. The logo is automatically positioned at the bottom-left corner with standardized sizing (1/15 of plot height, square).
add_bfh_logo(plot, logo_path = NULL, alpha = 1)add_bfh_logo(plot, logo_path = NULL, alpha = 1)
plot |
A ggplot2 object. |
logo_path |
Path to a PNG or JPEG logo file. When 'NULL' (default), uses the packaged BFH mark logo ('bfh_mark.png'). |
alpha |
Transparency of the logo (0–1). Defaults to '1' (fully opaque). A value of '0' produces an invisible logo. |
**Simplified API (v0.3.0):** This function uses fixed positioning to ensure consistent branding across all visualizations. The logo is always placed at the bottom-left corner, flush with the plot edge, at a height and width of 1/15 of the total plot height (square aspect ratio).
**Default logo:** When 'logo_path = NULL', the function automatically loads 'bfh_mark.png' (full resolution BFH symbol mark). For custom logos, provide a path to a PNG or JPEG file.
**Dependencies:** Requires the 'cowplot' package for precise logo positioning. Install with: “'r install.packages("cowplot") “'
**Path restriction:** Restrict logo loading to a specific directory (path-prefix check, not a security sandbox): “'r options(BFHtheme.logo_root = "/approved/logo/directory") “' When set, only logos within this directory (or subdirectories) will be allowed.
**Resource limits:** Maximum file size and image dimensions can be configured: “'r options(BFHtheme.logo_max_bytes = 5 * 1024^2) # 5 MB default options(BFHtheme.logo_max_dim = 4096) # 4096 px default “'
**Performance:** Decoded logo images are cached per path and file modification time. Repeated calls with the same unchanged file avoid redundant disk reads.
**Breaking changes from v0.2.0:** The 'position', 'size', and 'padding' parameters have been removed to enforce consistent branding. See NEWS.md for migration guidance.
Modified ggplot2 object with the logo applied.
[get_bfh_logo()], [add_bfh_footer()]
Other BFH branding:
add_bfh_footer(),
bfh_title_block(),
get_bfh_logo()
## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Use default BFH mark logo (recommended) add_bfh_logo(p) # Use custom logo add_bfh_logo(p, logo_path = "/path/to/custom_logo.png") # Adjust transparency add_bfh_logo(p, alpha = 0.7) ## End(Not run)## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Use default BFH mark logo (recommended) add_bfh_logo(p) # Use custom logo add_bfh_logo(p, logo_path = "/path/to/custom_logo.png") # Adjust transparency add_bfh_logo(p, alpha = 0.7) ## End(Not run)
Master vector of Bispebjerg og Frederiksberg Hospital and Region Hovedstaden brand colors. Values are hex codes that comply with the official visual identity guidelines.
bfh_colorsbfh_colors
A named character vector where each element is a hex color code.
The object exposes both official color names (e.g. '"hospital_primary"') and pragmatic aliases (e.g. '"primary"', '"blue"') for quick scripting. Use [bfh_cols()] to extract colors safely with validation and helpful error messages.
[bfh_cols()], [bfh_palettes], [show_bfh_palettes()]
Other BFH colors:
bfh_cols(),
bfh_pal(),
bfh_palettes,
clear_bfh_pal_cache(),
show_bfh_palettes()
Retrieves one or more BFH brand colors by name with validation and friendly error messages.
bfh_cols(...)bfh_cols(...)
... |
Character names present in [bfh_colors]. If omitted, all colors are returned. |
The function accepts both official color identifiers (e.g. '"hospital_primary"') and provided aliases (e.g. '"primary"'). Invalid names trigger an informative error listing available options.
Character vector of hex color codes in the order requested.
Other BFH colors:
bfh_colors,
bfh_pal(),
bfh_palettes,
clear_bfh_pal_cache(),
show_bfh_palettes()
# Get a single color bfh_cols("primary") # Get multiple colors bfh_cols("hospital_primary", "hospital_blue") # Get all colors bfh_cols() # Using aliases bfh_cols("blue", "grey")# Get a single color bfh_cols("primary") # Get multiple colors bfh_cols("hospital_primary", "hospital_blue") # Get all colors bfh_cols() # Using aliases bfh_cols("blue", "grey")
Arranges multiple ggplot2 plots into a single layout with an optional shared legend, ideal for BFH report panels and slide decks.
bfh_combine_plots(plots, ncol = NULL, nrow = NULL, legend_position = "bottom")bfh_combine_plots(plots, ncol = NULL, nrow = NULL, legend_position = "bottom")
plots |
List of ggplot2 plot objects. |
ncol |
Optional number of columns in the layout. |
nrow |
Optional number of rows in the layout. |
legend_position |
Legend placement. One of '"bottom"', '"top"', '"left"', '"right"', or '"none"'. Defaults to '"bottom"'. |
The function currently depends on the 'patchwork' package. When unavailable a descriptive error is raised; install 'patchwork' to use this helper.
Combined plot object produced by 'patchwork'.
[patchwork::wrap_plots()], [bfh_save()]
Other BFH helpers:
bfh_labs(),
bfh_save(),
get_bfh_dimensions()
## Not run: library(ggplot2) p1 <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() p2 <- ggplot(mtcars, aes(hp, mpg, color = factor(cyl))) + geom_point() p3 <- ggplot(mtcars, aes(disp, mpg, color = factor(cyl))) + geom_point() # Combine with shared legend bfh_combine_plots(list(p1, p2, p3), ncol = 3) ## End(Not run)## Not run: library(ggplot2) p1 <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() p2 <- ggplot(mtcars, aes(hp, mpg, color = factor(cyl))) + geom_point() p3 <- ggplot(mtcars, aes(disp, mpg, color = factor(cyl))) + geom_point() # Combine with shared legend bfh_combine_plots(list(p1, p2, p3), ncol = 3) ## End(Not run)
Wrapper around [ggplot2::labs()] that converts subtitles, captions, axes, and legend titles to uppercase, matching BFH typographic guidance while leaving the main title unchanged.
bfh_labs(...)bfh_labs(...)
... |
Named arguments passed to [ggplot2::labs()]. Character values are uppercased except for 'title'. Common keys include:
|
Only the argument named '"title"' is exempt from uppercasing. Supply other character values via '...' and they will be converted using [base::toupper()].
A ggplot2 labels object.
[ggplot2::labs()], [bfh_title_block()]
Other BFH helpers:
bfh_combine_plots(),
bfh_save(),
get_bfh_dimensions()
## Not run: library(ggplot2) # Only title unchanged, everything else uppercase ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() + bfh_labs( title = "Fuel efficiency analysis", # → "Fuel efficiency analysis" (unchanged) subtitle = "Motor Trend data", # → "MOTOR TREND DATA" x = "weight (tons)", # → "WEIGHT (TONS)" y = "miles per gallon" # → "MILES PER GALLON" ) # Time series example ggplot(time_data, aes(date, value, color = group)) + geom_line() + theme_bfh() + bfh_labs( title = "Patient trends over time", # → "Patient trends over time" (unchanged) subtitle = "Bispebjerg og Frederiksberg Hospital 2020-2024", # → "BISPEBJERG..." (uppercase) x = "date", # → "DATE" y = "number of patients", # → "NUMBER OF PATIENTS" color = "department" # → "DEPARTMENT" ) ## End(Not run)## Not run: library(ggplot2) # Only title unchanged, everything else uppercase ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() + bfh_labs( title = "Fuel efficiency analysis", # → "Fuel efficiency analysis" (unchanged) subtitle = "Motor Trend data", # → "MOTOR TREND DATA" x = "weight (tons)", # → "WEIGHT (TONS)" y = "miles per gallon" # → "MILES PER GALLON" ) # Time series example ggplot(time_data, aes(date, value, color = group)) + geom_line() + theme_bfh() + bfh_labs( title = "Patient trends over time", # → "Patient trends over time" (unchanged) subtitle = "Bispebjerg og Frederiksberg Hospital 2020-2024", # → "BISPEBJERG..." (uppercase) x = "date", # → "DATE" y = "number of patients", # → "NUMBER OF PATIENTS" color = "department" # → "DEPARTMENT" ) ## End(Not run)
Creates a color interpolation function for any named palette in [bfh_palettes], enabling smooth gradients or truncated palette selections.
bfh_pal(palette = "main", reverse = FALSE, ...)bfh_pal(palette = "main", reverse = FALSE, ...)
palette |
Character name of the palette in [bfh_palettes]. Defaults to '"main"'. |
reverse |
Logical; reverse the palette order. Defaults to 'FALSE'. |
... |
Additional arguments forwarded to [grDevices::colorRampPalette()]. |
Function that accepts an integer 'n' and returns 'n' colors.
[bfh_palettes], [scale_color_bfh()], [scale_fill_bfh()]
Other BFH colors:
bfh_colors,
bfh_cols(),
bfh_palettes,
clear_bfh_pal_cache(),
show_bfh_palettes()
bfh_pal("main")(5) bfh_pal("blues", reverse = TRUE)(3)bfh_pal("main")(5) bfh_pal("blues", reverse = TRUE)(3)
Predefined discrete and sequential palettes covering hospital, regional, and legacy BFH use cases. Palettes are sourced from [bfh_colors].
bfh_palettesbfh_palettes
An object of class list of length 16.
The list is structured for use with [bfh_pal()] and the 'scale_*_bfh*()' helpers. Palettes ending in '"_seq"' are suited for continuous scales while the rest target categorical data and infographics.
[bfh_pal()], [show_bfh_palettes()], [scale_color_bfh()]
Other BFH colors:
bfh_colors,
bfh_cols(),
bfh_pal(),
clear_bfh_pal_cache(),
show_bfh_palettes()
Wrapper around [ggplot2::ggsave()] that applies BFH-recommended dimensions, resolution, and message output for reproducible plot exports.
bfh_save( filename, plot = ggplot2::last_plot(), preset = "report_full", width = NULL, height = NULL, units = "in", dpi = 300, ... )bfh_save( filename, plot = ggplot2::last_plot(), preset = "report_full", width = NULL, height = NULL, units = "in", dpi = 300, ... )
filename |
File name to save the plot. Include an extension such as '"plot.png"' or '"figure.pdf"'. |
plot |
Plot to save. Defaults to the last displayed plot. |
preset |
Character string specifying size presets: '"report_full"' (7x5 in), '"report_half"' (3.5x3 in), '"presentation"' (10x6 in), '"presentation_wide"' (12x6.75 in), '"square"' (6x6 in), '"poster"' (12x9 in). |
width |
Plot width. Overrides 'preset' when provided. |
height |
Plot height. Overrides 'preset' when provided. |
units |
Units for width/height ('"in"', '"cm"', '"mm"', '"px"'). Defaults to '"in"'. |
dpi |
Resolution in dots per inch. Defaults to 300. |
... |
Additional arguments passed to [ggplot2::ggsave()]. |
Use the 'preset' argument to quickly match internal communication formats. Width/height arguments override presets when supplied. For more control, pair with [get_bfh_dimensions()] to retrieve structured size guidance.
Invisibly returns 'filename'.
[get_bfh_dimensions()], [theme_bfh()], [bfh_title_block()]
Other BFH helpers:
bfh_combine_plots(),
bfh_labs(),
get_bfh_dimensions()
## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Save with preset bfh_save("my_plot.png", p, preset = "report_full") # Save with custom dimensions bfh_save("my_plot.pdf", p, width = 8, height = 6, dpi = 600) ## End(Not run)## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Save with preset bfh_save("my_plot.png", p, preset = "report_full") # Save with custom dimensions bfh_save("my_plot.pdf", p, width = 8, height = 6, dpi = 600) ## End(Not run)
Generates a reusable set of labels for BFH-styled titles, subtitles, and captions.
bfh_title_block(title, subtitle = NULL, caption = NULL)bfh_title_block(title, subtitle = NULL, caption = NULL)
title |
Main title text. |
subtitle |
Optional subtitle text. |
caption |
Optional caption text. |
Pair with [bfh_labs()] for automatic uppercase conversion or add the result directly to ggplot objects. Use 'NULL' for optional arguments you want to omit.
A [ggplot2::labs] object.
[bfh_labs()], [theme_bfh()], [add_bfh_footer()]
Other BFH branding:
add_bfh_footer(),
add_bfh_logo(),
get_bfh_logo()
## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + bfh_title_block( title = "Vehicle Weight vs Fuel Efficiency", subtitle = "Analysis of mtcars dataset", caption = "Source: Motor Trend, 1974" ) + theme_bfh() ## End(Not run)## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + bfh_title_block( title = "Vehicle Weight vs Fuel Efficiency", subtitle = "Analysis of mtcars dataset", caption = "Source: Motor Trend, 1974" ) + theme_bfh() ## End(Not run)
Identifies the best available typeface for BFH-branded plots, caching the result to avoid repeated system queries. The priority order is: Mari → Mari Office → Roboto → Arial → sans.
get_bfh_font(check_installed = TRUE, silent = FALSE, force_refresh = FALSE)get_bfh_font(check_installed = TRUE, silent = FALSE, force_refresh = FALSE)
check_installed |
Logical. If 'TRUE' (default) verify fonts are installed. Set to 'FALSE' to simply return the highest-priority font name. |
silent |
Logical. Suppress informational messages when 'TRUE'. Defaults to 'FALSE'. |
force_refresh |
Logical. When 'TRUE', bypass the cache and re-run the detection. Defaults to 'FALSE'. |
Font availability is checked via 'systemfonts::system_fonts()' exact family name matching, which is reliable across platforms.
Results are cached in the package environment; use [clear_bfh_font_cache()] or set 'force_refresh = TRUE' after installing new fonts.
**Font availability notes:** - **Mari fonts**: Only available on BFH employee computers (proprietary) - **Roboto**: Free open-source font (install via OS or use 'use_bfh_showtext()') - **Arial**: System font on most platforms - **sans**: Universal fallback (system default)
**For embedding fonts in outputs:** Use modern graphics devices like 'ragg::agg_png()', 'svglite::svglite()', or 'grDevices::cairo_pdf()'. See 'set_bfh_graphics()' for recommended device setup.
Character string containing the selected font family.
[check_bfh_fonts()], [set_bfh_fonts()], [set_bfh_defaults()]
Other BFH fonts:
check_bfh_fonts(),
clear_bfh_font_cache(),
install_roboto_font(),
set_bfh_fonts(),
set_bfh_graphics(),
setup_bfh_fonts(),
use_bfh_showtext()
# Get best available font (cached after first call) font <- get_bfh_font() # Use in theme theme_bfh(base_family = get_bfh_font()) # Force refresh cache if fonts change font <- get_bfh_font(force_refresh = TRUE) # For external users without Mari fonts: # Install showtext for automatic Roboto loading ## Not run: install.packages("showtext") library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Roboto will be auto-loaded via Google Fonts if not installed ## End(Not run)# Get best available font (cached after first call) font <- get_bfh_font() # Use in theme theme_bfh(base_family = get_bfh_font()) # Force refresh cache if fonts change font <- get_bfh_font(force_refresh = TRUE) # For external users without Mari fonts: # Install showtext for automatic Roboto loading ## Not run: install.packages("showtext") library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Roboto will be auto-loaded via Google Fonts if not installed ## End(Not run)
Retrieves the file path to BFH logo assets bundled with the package. Variants include full colour, greyscale, and symbol-only marks across multiple resolutions.
get_bfh_logo(size = "web", variant = "color")get_bfh_logo(size = "web", variant = "color")
size |
Logo size: '"full"' (print resolution), '"web"' (800 px), or '"small"' (400 px). Defaults to '"web"'. |
variant |
Logo variant: '"color"' (default), '"grey"' (greyscale), or '"mark"' (symbol only). |
Character string containing the absolute path, or 'NULL' if the asset is unavailable.
[add_bfh_logo()]
Other BFH branding:
add_bfh_footer(),
add_bfh_logo(),
bfh_title_block()
## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Add BFH logo to plot add_bfh_logo(p, get_bfh_logo()) # Use high-resolution version for print add_bfh_logo(p, get_bfh_logo("full")) # Use greyscale logo add_bfh_logo(p, get_bfh_logo(variant = "grey")) # Use mark (symbol only) add_bfh_logo(p, get_bfh_logo(variant = "mark")) ## End(Not run)## Not run: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() # Add BFH logo to plot add_bfh_logo(p, get_bfh_logo()) # Use high-resolution version for print add_bfh_logo(p, get_bfh_logo("full")) # Use greyscale logo add_bfh_logo(p, get_bfh_logo(variant = "grey")) # Use mark (symbol only) add_bfh_logo(p, get_bfh_logo(variant = "mark")) ## End(Not run)
Restores the theme and geom defaults that were active before [set_bfh_defaults()] was last called.
reset_bfh_defaults()reset_bfh_defaults()
If [set_bfh_defaults()] has not been called in the current session, falls back to ‘theme_gray()' and ggplot2’s hardcoded geom defaults, and emits a message indicating no saved state was found.
Invisibly returns 'TRUE' once defaults are reset.
[set_bfh_defaults()]
Other BFH defaults:
set_bfh_defaults(),
use_bfh_knitr_defaults()
## Not run: # Set BFH defaults set_bfh_defaults() # ... create some plots ... # Reset to previous state reset_bfh_defaults() ## End(Not run)## Not run: # Set BFH defaults set_bfh_defaults() # ... create some plots ... # Reset to previous state reset_bfh_defaults() ## End(Not run)
Convenient wrappers around ggplot2 scales that apply BFH brand palettes to colour or fill aesthetics.
scale_color_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_colour_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_fill_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...)scale_color_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_colour_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...) scale_fill_bfh(palette = "main", discrete = TRUE, reverse = FALSE, ...)
palette |
Character name of a palette in [bfh_palettes()]. Defaults to '"main"'. |
discrete |
Logical; treat the mapped variable as discrete? Defaults to 'TRUE'. |
reverse |
Logical; reverse the palette order? Defaults to 'FALSE'. |
... |
Additional arguments passed to the underlying ggplot2 scale functions. |
When 'discrete = TRUE' the functions delegate to [ggplot2::discrete_scale()]. For continuous aesthetics they build a gradient using [bfh_pal()] and [ggplot2::scale_color_gradientn()] / [ggplot2::scale_fill_gradientn()]. Set 'reverse = TRUE' to invert palette order, and pass additional arguments via '...' to fine-tune scale behaviour.
A ggplot2 scale object.
[bfh_pal()], [bfh_palettes], [scale_fill_bfh_continuous()]
Other BFH scales:
scale_fill_bfh_continuous(),
scale_fill_bfh_discrete(),
scale_position_bfh
## Not run: library(ggplot2) ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) + geom_point() + scale_color_bfh() ## End(Not run) ## Not run: library(ggplot2) ggplot(mtcars, aes(x = factor(cyl), fill = factor(cyl))) + geom_bar() + scale_fill_bfh() ## End(Not run)## Not run: library(ggplot2) ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) + geom_point() + scale_color_bfh() ## End(Not run) ## Not run: library(ggplot2) ggplot(mtcars, aes(x = factor(cyl), fill = factor(cyl))) + geom_bar() + scale_fill_bfh() ## End(Not run)
Continuous colour scales using specific BFH palettes
scale_fill_bfh_continuous(palette = "blues", reverse = FALSE, ...) scale_color_bfh_continuous(palette = "blues", reverse = FALSE, ...) scale_colour_bfh_continuous(palette = "blues", reverse = FALSE, ...)scale_fill_bfh_continuous(palette = "blues", reverse = FALSE, ...) scale_color_bfh_continuous(palette = "blues", reverse = FALSE, ...) scale_colour_bfh_continuous(palette = "blues", reverse = FALSE, ...)
palette |
Character name of a palette in [bfh_palettes()]. |
reverse |
Logical; reverse palette direction? Defaults to 'FALSE'. |
... |
Additional arguments passed to [ggplot2::scale_color_gradientn()]. |
[scale_color_bfh()], [bfh_pal()]
Other BFH scales:
scale_bfh,
scale_fill_bfh_discrete(),
scale_position_bfh
## Not run: library(ggplot2) ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_tile() + scale_fill_bfh_continuous(palette = "blues") ## End(Not run)## Not run: library(ggplot2) ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_tile() + scale_fill_bfh_continuous(palette = "blues") ## End(Not run)
Discrete colour scales using specific BFH palettes
scale_fill_bfh_discrete(palette = "main", reverse = FALSE, ...) scale_color_bfh_discrete(palette = "main", reverse = FALSE, ...) scale_colour_bfh_discrete(palette = "main", reverse = FALSE, ...)scale_fill_bfh_discrete(palette = "main", reverse = FALSE, ...) scale_color_bfh_discrete(palette = "main", reverse = FALSE, ...) scale_colour_bfh_discrete(palette = "main", reverse = FALSE, ...)
palette |
Character name of a palette in [bfh_palettes()]. |
reverse |
Logical; reverse palette direction? Defaults to 'FALSE'. |
... |
Additional arguments passed to [ggplot2::discrete_scale()]. |
[scale_color_bfh()], [bfh_pal()], [bfh_palettes]
Other BFH scales:
scale_bfh,
scale_fill_bfh_continuous(),
scale_position_bfh
## Not run: library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_bfh_discrete(palette = "primary") ## End(Not run)## Not run: library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_bfh_discrete(palette = "primary") ## End(Not run)
Position scale functions that automatically convert axis tick labels to uppercase, following BFH typography guidelines. These functions wrap ggplot2's standard position scales and apply uppercase transformation to all axis labels.
scale_x_continuous_bfh(..., labels = toupper) scale_y_continuous_bfh(..., labels = toupper) scale_x_discrete_bfh(..., labels = toupper) scale_y_discrete_bfh(..., labels = toupper) scale_x_date_bfh(..., date_labels = waiver(), labels = waiver()) scale_y_date_bfh(..., date_labels = waiver(), labels = waiver()) scale_x_datetime_bfh(..., date_labels = waiver(), labels = waiver()) scale_y_datetime_bfh(..., date_labels = waiver(), labels = waiver())scale_x_continuous_bfh(..., labels = toupper) scale_y_continuous_bfh(..., labels = toupper) scale_x_discrete_bfh(..., labels = toupper) scale_y_discrete_bfh(..., labels = toupper) scale_x_date_bfh(..., date_labels = waiver(), labels = waiver()) scale_y_date_bfh(..., date_labels = waiver(), labels = waiver()) scale_x_datetime_bfh(..., date_labels = waiver(), labels = waiver()) scale_y_datetime_bfh(..., date_labels = waiver(), labels = waiver())
... |
Additional arguments passed to the underlying ggplot2 scale function. Common arguments include 'breaks', 'limits', 'expand', etc. |
labels |
Label formatting function. For date/datetime scales, defaults to 'waiver()' which uses 'scales::label_date_short()' for compact, hierarchical labels. For other scales, defaults to 'toupper'. You can pass any 'scales::label_*()'function (e.g., 'label_date(" and output will be uppercased automatically. Set to 'waiver()' to use the 'date_labels' parameter for date/datetime scales. |
date_labels |
Date format string using standard strftime format codes (e.g., '" scales. When 'labels = waiver()', this parameter controls the date format via 'scales::label_date(format = date_labels)'. Output is automatically uppercased. If 'labels' is explicitly specified, 'date_labels' is ignored. Defaults to 'waiver()' which uses 'label_date_short()'. |
These functions are particularly useful for maintaining consistent typographic style across plots. The uppercase transformation is applied via the 'labels' argument, which accepts a function that formats the axis breaks.
For date and datetime scales, **the default is [scales::label_date_short()]** which creates compact, hierarchical labels that only show what has changed (e.g., year only appears when it changes). This minimizes horizontal space on the x-axis. All output is automatically converted to uppercase.
## Default Behavior (label_date_short)
By default, date/datetime scales use 'label_date_short()' which produces: “' JAN. | FEB. | MAR. | ... | DEC. | JAN. | FEB. | ... 2023 2024 “' Instead of the repetitive: “' JAN. 2023 | FEB. 2023 | MAR. 2023 | ... | JAN. 2024 | FEB. 2024 | ... “'
## Integration with scales package
The date/datetime scales integrate seamlessly with the 'scales' package. You can override the default or use 'breaks_pretty()' for intelligent break positioning:
“'r # Use default (label_date_short with smart breaks) scale_x_date_bfh()
# Add custom breaks scale_x_date_bfh(breaks = scales::breaks_pretty(n = 6))
# Override with custom label format scale_x_date_bfh(labels = scales::label_date("
# Combine custom breaks and labels scale_x_date_bfh( breaks = scales::breaks_pretty(n = 8), labels = scales::label_date(" ) “'
A ggplot2 scale object.
[ggplot2::scale_x_continuous()], [ggplot2::scale_x_discrete()], [ggplot2::scale_x_date()], [bfh_labs()], [scales::label_date()], [scales::label_date_short()], [scales::breaks_pretty()]
Other BFH scales:
scale_bfh,
scale_fill_bfh_continuous(),
scale_fill_bfh_discrete()
## Not run: library(ggplot2) # Continuous scale with uppercase labels ggplot(mtcars, aes(wt, mpg)) + geom_point() + scale_x_continuous_bfh() + theme_bfh() # Discrete scale with uppercase labels ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_boxplot() + scale_x_discrete_bfh() + theme_bfh() # Date scale with default label_date_short() (compact hierarchical labels) df <- data.frame( date = seq.Date(as.Date("2023-01-01"), as.Date("2024-12-31"), by = "month"), value = rnorm(24) ) ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh() + # Uses label_date_short() by default! theme_bfh() # Add custom breaks for better positioning ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(breaks = scales::breaks_pretty(n = 8)) + theme_bfh() # Override with custom label format using labels parameter ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(labels = scales::label_date("%B %Y")) + # Full month names theme_bfh() # Or use date_labels parameter for simple format strings ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(date_labels = "%Y") + # Year only (uppercased) theme_bfh() # Another date_labels example: custom format ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(date_labels = "%Y-%m-%d") + # ISO date format theme_bfh() ## End(Not run)## Not run: library(ggplot2) # Continuous scale with uppercase labels ggplot(mtcars, aes(wt, mpg)) + geom_point() + scale_x_continuous_bfh() + theme_bfh() # Discrete scale with uppercase labels ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_boxplot() + scale_x_discrete_bfh() + theme_bfh() # Date scale with default label_date_short() (compact hierarchical labels) df <- data.frame( date = seq.Date(as.Date("2023-01-01"), as.Date("2024-12-31"), by = "month"), value = rnorm(24) ) ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh() + # Uses label_date_short() by default! theme_bfh() # Add custom breaks for better positioning ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(breaks = scales::breaks_pretty(n = 8)) + theme_bfh() # Override with custom label format using labels parameter ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(labels = scales::label_date("%B %Y")) + # Full month names theme_bfh() # Or use date_labels parameter for simple format strings ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(date_labels = "%Y") + # Year only (uppercased) theme_bfh() # Another date_labels example: custom format ggplot(df, aes(date, value)) + geom_line() + scale_x_date_bfh(date_labels = "%Y-%m-%d") + # ISO date format theme_bfh() ## End(Not run)
Applies a BFH theme globally and updates default geom colours for the current R session. Ideal for scripts or reports where every plot should inherit BFH styling without repeated boilerplate.
set_bfh_defaults( theme = "bfh", palette = "main", base_size = 12, base_family = NULL )set_bfh_defaults( theme = "bfh", palette = "main", base_size = 12, base_family = NULL )
theme |
Character name of the BFH theme to adopt. Only '"bfh"' is supported (other theme variants removed in v0.2.0). Defaults to '"bfh"'. |
palette |
Character name of the palette from [bfh_palettes] used to seed geom defaults. Defaults to '"main"'. |
base_size |
Base font size for the theme. Defaults to 12. |
base_family |
Base font family. Use 'NULL' (default) to auto-detect with [get_bfh_font()]. |
The function calls [ggplot2::theme_set()] with the selected BFH theme and updates default aesthetics for commonly used geoms (points, lines, bars, and more). Colour/fill scales are not altered automatically—continue to add 'scale_*_bfh()' when mapping aesthetics.
Previous global state (active theme and geom defaults) is saved automatically and can be restored with [reset_bfh_defaults()].
Invisibly returns 'TRUE' after the defaults have been applied.
[reset_bfh_defaults()], [set_bfh_fonts()]
Other BFH defaults:
reset_bfh_defaults(),
use_bfh_knitr_defaults()
## Not run: # Set BFH defaults at the start of your script set_bfh_defaults() # Plots without color mapping use BFH colors automatically library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() # Uses BFH primary color # For color mappings, add scale manually ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() + scale_color_bfh() # Required for BFH colors # Use a different palette set_bfh_defaults(palette = "blues") ## End(Not run)## Not run: # Set BFH defaults at the start of your script set_bfh_defaults() # Plots without color mapping use BFH colors automatically library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() # Uses BFH primary color # For color mappings, add scale manually ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() + scale_color_bfh() # Required for BFH colors # Use a different palette set_bfh_defaults(palette = "blues") ## End(Not run)
Displays every palette defined in [bfh_palettes] using 'scales::show_col()' to assist with palette selection.
show_bfh_palettes(n = NULL)show_bfh_palettes(n = NULL)
n |
Optional integer specifying how many colors to preview from each palette. When 'NULL' (default) all palette entries are shown. |
Other BFH colors:
bfh_colors,
bfh_cols(),
bfh_pal(),
bfh_palettes,
clear_bfh_pal_cache()
## Not run: show_bfh_palettes() ## End(Not run)## Not run: show_bfh_palettes() ## End(Not run)
Primary ggplot2 theme aligned with Bispebjerg og Frederiksberg Hospital's visual identity guidelines. Applies typography, spacing, and layout defaults that mirror official templates.
theme_bfh( base_size = 12, base_family = NULL, base_line_size = base_size/22, base_rect_size = base_size/22 )theme_bfh( base_size = 12, base_family = NULL, base_line_size = base_size/22, base_rect_size = base_size/22 )
base_size |
Base font size in points. Default is 12. |
base_family |
Base font family. Set to 'NULL' (default) to auto-detect a BFH approved font via [get_bfh_font()]. |
base_line_size |
Base line size. Default is 'base_size / 22'. |
base_rect_size |
Base rectangle size. Default is 'base_size / 22'. |
The theme builds on 'ggplot2::theme_minimal()' and augments it with BFH-specific typography via 'marquee::element_marquee', custom axis styling, and legend placement. When 'base_family = NULL' (the default) the best available BFH font is detected automatically using [get_bfh_font()]. Use the 'base_*' arguments to fine-tune typography while preserving the brand aesthetic.
A [ggplot2::theme] object that can be added to ggplot graphs.
## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() ## End(Not run)## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh() ## End(Not run)
Sets knitr chunk options to use ragg-based rendering at 300 DPI — the recommended output device for BFH-styled graphics in R Markdown and Quarto documents.
use_bfh_knitr_defaults(dpi = 300)use_bfh_knitr_defaults(dpi = 300)
dpi |
Output resolution in dots per inch. Defaults to '300'. |
**This function must be called explicitly.** 'library(BFHtheme)' does NOT modify knitr options automatically. This is intentional: modifying global session state on package load would silently override any knitr configuration the user has already set.
Call 'use_bfh_knitr_defaults()' once in your setup chunk:
library(BFHtheme) use_bfh_knitr_defaults()
Requires the 'ragg' package. Install with 'install.packages("ragg")'.
Invisibly returns 'NULL'. Called for its side effect of setting knitr chunk options.
[set_bfh_defaults()]
Other BFH defaults:
reset_bfh_defaults(),
set_bfh_defaults()
## Not run: library(BFHtheme) use_bfh_knitr_defaults() # knitr::opts_chunk$get("dev") is now "ragg_png" ## End(Not run)## Not run: library(BFHtheme) use_bfh_knitr_defaults() # knitr::opts_chunk$get("dev") is now "ragg_png" ## End(Not run)