Adding Corporate Colors to R Graphs

Creating consistent visuals can elevate your brand, and customizing your ggplots with your corporate colors is a simple way to achieve that. The video and R code below will walk you through setting up your color palette and applying it to your plots. Together they provide an easy path to producing graphics that look polished and aligned with your organization’s style.

This video shows you how to build a reusable corporate color system in R, including custom palettes, ggplot scales and a clean theme that matches your organization’s brand. You will see how to apply it across different chart types so your reports and presentations look consistent and professional.


Subscribe to get smarter with updates on my latest videos, courses, and more.



library(ggplot2)
library(scales)

# -------------------------------------------------------------------------
# 1. Define the Corporate Colors
# -------------------------------------------------------------------------
# Replace these hex codes with your actual corporate brand colors
corp_colors <- c(
  primary   = "#005587",  # Example: Strong Blue
  secondary = "#4D4D4F",  # Example: Dark Grey
  accent    = "#F2A900",  # Example: Bright Orange
  highlight = "#279989",  # Example: Teal
  neutral   = "#E2E2E2"   # Example: Light Grey
)

# Optional palette list for future expansion
corp_palettes <- list(
  main = corp_colors
)

# -------------------------------------------------------------------------
# 2. Helper Function to Retrieve Colors
# -------------------------------------------------------------------------
# This allows you to grab specific hex codes by name: corp_cols("primary")
corp_cols <- function(...) {
  cols <- c(...)
  if (length(cols) == 0) 
    return(corp_colors)
  corp_colors[cols]
}

# -------------------------------------------------------------------------
# 3. Palette Function (Interpolation)
# -------------------------------------------------------------------------
# This generates a palette function. If you request more colors than exist
# in your list, it automatically interpolates (blends) them.
corp_pal <- function(palette = "main", reverse = FALSE, ...) {
  pal <- corp_palettes[[palette]]
  if (is.null(pal)) {
    stop("Unknown palette name. Available palettes: ",
         paste(names(corp_palettes), collapse = ", "))
  }
  if (reverse) pal <- rev(pal)
  colorRampPalette(pal, ...)
}

# -------------------------------------------------------------------------
# 4. Create the ggplot2 Scale Functions
# -------------------------------------------------------------------------

# Function for Color (lines, points)
scale_color_corporate <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
  pal <- corp_pal(palette, reverse)
  if (discrete) {
    discrete_scale("color", paste0("corp_", palette), palette = pal, ...)
  } else {
    scale_color_gradientn(colors = pal(256), ...)
  }
}

# Function for Fill (bars, areas)
scale_fill_corporate <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
  pal <- corp_pal(palette, reverse)
  if (discrete) {
    discrete_scale("fill", paste0("corp_", palette), palette = pal, ...)
  } else {
    scale_fill_gradientn(colors = pal(256), ...)
  }
}

# -------------------------------------------------------------------------
# 5. Corporate Theme Function
# -------------------------------------------------------------------------
# Add font and styles

theme_corporate <- function(base_size = 12, base_family = "") {
  theme_minimal(base_size = base_size, base_family = base_family) +
    theme(
      plot.title = element_text(color = corp_colors["primary"], face = "bold"),
      axis.title = element_text(color = corp_colors["secondary"]),
      axis.text  = element_text(color = corp_colors["secondary"]),
      panel.grid.major = element_line(color = corp_colors["neutral"]),
      panel.grid.minor = element_blank()
    )
}

# -------------------------------------------------------------------------
# 6. Usage Examples
# -------------------------------------------------------------------------

# Generate dummy data
set.seed(123)
df <- data.frame(
  category = c("A", "B", "C", "D", "E"),
  value = runif(5, 10, 100),
  x = rnorm(50),
  y = rnorm(50),
  group = sample(c("A", "B", "C"), 50, replace = TRUE)
)

# Example 1: Discrete Fill (Bar Chart)
p1 <- ggplot(df, aes(x = category, y = value, fill = category)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Discrete Fill Example") +
  scale_fill_corporate() # <--- Apply custom fill

# Example 2: Discrete Color (Scatter Plot)
p2 <- ggplot(df, aes(x = x, y = y, color = group)) +
  geom_point(size = 3) +
  theme_minimal() +
  labs(title = "Discrete Color Example") +
  scale_color_corporate() # <--- Apply custom color

# Example 3: Continuous Color (Heatmap style)
p3 <- ggplot(df, aes(x = x, y = y, color = x)) +
  geom_point(size = 3) +
  theme_minimal() +
  labs(title = "Continuous Gradient Example") +
  scale_color_corporate(discrete = FALSE) # <--- Apply continuous gradient

# Print plots (if running interactively)
p1
p2
p2+theme_corporate()
p3