BFH Theme and Color Palettes for ggplot2
A comprehensive R package providing theming support for ggplot2 graphics following the visual identity guidelines of Bispebjerg og Frederiksberg Hospital (BFH).
- Multiple Color Palettes: Predefined palettes following BFH branding
- Theme Functions: Optimized themes for reports, presentations, and print
- Scale Functions: Easy-to-use color and fill scales for ggplot2
- Helper Utilities: Functions for saving plots with correct dimensions
- Branding Tools: Add logos, watermarks, and footers to your plots
- Global Defaults: Set BFH styling as default for all plots in a session
# Install from local package file
install.packages("BFHtheme_0.1.0.tar.gz", repos = NULL, type = "source")
# Or install from directory
devtools::install_local("/path/to/BFHtheme")
# Or if hosted on GitHub (update with your repo)
# devtools::install_github("yourusername/BFHtheme")For best typography results, especially for external users without access to BFH's proprietary Mari font:
install.packages("showtext")This enables automatic Roboto font loading from Google Fonts. See Typography section for details.
Note: Efter installation, genstart din R session for at sikre pakken er korrekt loaded.
library(BFHtheme)
library(ggplot2)
# Set BFH defaults for all plots
set_bfh_defaults()
# Create a plot - it will automatically use BFH theme and colors
ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point(size = 3) +
bfh_labs(
title = "Vehicle weight vs fuel efficiency", # Natural case for titles
x = "weight (1000 lbs)", # Uppercase for axes
y = "miles per gallon" # Uppercase for axes
)ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_bfh() +
labs(title = "A Professional BFH Plot")# Discrete colors
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() +
scale_color_bfh(palette = "primary") +
theme_bfh()
# Continuous colors
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
geom_tile() +
scale_fill_bfh_continuous(palette = "blues") +
theme_bfh()theme_bfh()- Main BFH theme (customizable via additionaltheme()calls)
Based on Region Hovedstaden's official visual identity guidelines:
Hospital Palettes (Bispebjerg og Frederiksberg Hospital):
hospital/main- Primary hospital colors for general usehospital_blues- Blue color gradient (hospital primary to light blue)hospital_blues_seq- Sequential blue palette including whitehospital_infographic- Optimized for hospital infographics
Region Hovedstaden Palettes (Koncern):
regionh- Primary Region H colorsregionh_main- Main Region H paletteregionh_blues- Region H blue gradientregionh_blues_seq- Sequential Region H blue palette including whiteregionh_infographic- Optimized for Region H infographics
Legacy/Compatibility Palettes:
primary- Core identity colorsblues/blues_sequential- Blue gradientsgreys- Grey to light blue palettecontrast- High contrast colors for accessibilityinfographic- General infographic palette
View all palettes:
show_bfh_palettes()p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_bfh()
# Use presets for common sizes
bfh_save("my_plot.png", p, preset = "report_full")
bfh_save("presentation.png", p, preset = "presentation")
# Or specify custom dimensions
bfh_save("custom.png", p, width = 10, height = 6, dpi = 600)The package includes bfh_labs() which automatically converts axis labels, subtitles, and legend titles to uppercase, while keeping the main plot title in natural case, following BFH visual identity conventions:
# Only title unchanged, everything else uppercase
ggplot(data, aes(date, value, color = group)) +
geom_line() +
theme_bfh() +
bfh_labs(
title = "Patient trends over time", # → "Patient trends over time" (unchanged)
subtitle = "2020-2024", # → "2020-2024" (UPPERCASE)
x = "date", # → "DATE"
y = "number of patients", # → "NUMBER OF PATIENTS"
color = "department" # → "DEPARTMENT"
)
# You can still use standard labs() if you prefer different styling
ggplot(data, aes(x, y)) +
geom_point() +
labs(title = "Custom Title", x = "custom x axis")Tip: Use bfh_labs() for consistency with BFH branding guidelines. Only the main title remains in natural case; subtitle, axis labels, and legend titles are automatically uppercased.
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bfh()
# Add BFH logo (included in package)
p_logo <- add_logo(p, position = "topright")
# Or specify logo path manually
p_logo <- add_bfh_logo(p, get_bfh_logo(), position = "topright")
# Add watermark
p_watermark <- add_watermark(p, text = "DRAFT", alpha = 0.3)
# Add footer
p_footer <- add_bfh_footer(p, text = "Bispebjerg og Frederiksberg Hospital - 2024")The package includes two sets of official colors:
Hospital Colors (Bispebjerg og Frederiksberg Hospital):
- Primary (Identitetsfarve):
#007dbb(RGB: 0,125,187) - Hospital Blue:
#009ce8(RGB: 0,156,232) - Light Blue 1:
#cce5f1(RGB: 204,211,221) - Light Blue 2:
#e5f2f8(RGB: 229,242,248) - Hospital Grey:
#646c6f(RGB: 100,108,111) - Dark Grey:
#333333(RGB: 51,51,51)
Region Hovedstaden Colors (Koncern):
- Primary (Identitetsfarve):
#002555(RGB: 0,37,85) - Navy - Region H Blue:
#007dbb(RGB: 0,125,187) - Light Grey 1:
#ccd3dd(RGB: 204,211,221) - Light Grey 2:
#e5e9ee(RGB: 229,233,238) - Region H Grey:
#646c6f(RGB: 100,108,111) - Dark Grey:
#333333(RGB: 51,51,51)
# View all colors
bfh_colors
# Access hospital colors
bfh_cols("hospital_primary", "hospital_blue")
# Access Region H colors
bfh_cols("regionh_primary", "regionh_blue")# Create a custom palette
my_palette <- bfh_cols("primary_blue", "orange", "teal", "purple")
# Use in a plot
ggplot(data, aes(x, y, color = group)) +
geom_point() +
scale_color_manual(values = my_palette)BFHtheme automatically selects the best available font using this priority order:
- Mari (BFH official font - available on BFH employee computers)
- Mari Office (alternative name on some systems)
- Roboto (free open-source alternative)
- Arial (system fallback)
- sans (universal fallback)
Recommended: Install showtext package for automatic Roboto loading:
# Install showtext
install.packages("showtext")
# Use BFHtheme - Roboto will be auto-loaded from Google Fonts if needed
library(BFHtheme)
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_bfh() # Roboto automatically loaded if Mari not availableAlternative: Manual Roboto installation
# Check which fonts are available
check_bfh_fonts()
# Get installation instructions
install_roboto_font()
# After installing Roboto, clear cache and verify
clear_bfh_font_cache()
check_bfh_fonts()For custom fonts:
# Example with showtext package
library(showtext)
font_add("YourFont", "path/to/font.ttf")
showtext_auto()
# Use in theme
theme_bfh(base_family = "YourFont")Note: Mari fonts are proprietary and only available on BFH employee computers. External users and collaborators should use Roboto (free, open-source, Apache 2.0 licensed) which provides excellent visual compatibility.
BFHtheme/
├── R/
│ ├── colors.R # Color palettes and utilities
│ ├── scales.R # ggplot2 scale functions
│ ├── themes.R # Theme functions
│ ├── defaults.R # Global defaults management
│ ├── helpers.R # Helper functions (saving, etc.)
│ ├── branding.R # Logo and branding functions
│ └── BFHtheme-package.R # Package documentation
├── inst/
│ └── examples/
│ └── basic_usage.R # Usage examples
├── man/ # Documentation (auto-generated)
├── DESCRIPTION
├── NAMESPACE
└── README.md
After modifying roxygen comments:
devtools::document()devtools::build()
devtools::check()source(system.file("examples/basic_usage.R", package = "BFHtheme"))We welcome contributions to BFHtheme! Please see CONTRIBUTING.md for detailed guidelines including:
- Package Architecture - Understand the module structure and where to add new code
- Utility Helper Conventions - Learn how to use
%||%operator and validation helpers - Caching Strategy - Understand session-level caching for fonts and palettes
- Development Workflow - Test-driven development process
- Code Style Guidelines - Naming conventions and coding patterns
- Testing Requirements - Coverage goals and test patterns
Quick checklist:
- Check existing issues before creating a new one
- Read the Package Architecture section to understand the codebase
- Use utility helpers for validation (
validate_*()functions and%||%operator) - Understand caching behavior and when to clear caches (
clear_bfh_font_cache(),clear_bfh_pal_cache()) - Follow the existing code style (snake_case, input validation,
call. = FALSEin errors) - Write tests for new features (≥90% coverage goal)
- Update documentation as needed (
devtools::document())
MIT License (update LICENSE file as needed)
Bispebjerg og Frederiksberg Hospital
Built with ggplot2 and inspired by other theme packages in the R community.
Note: Colors are based on Region Hovedstaden's official hospital visual identity guidelines (2024).