ggcustom
October 9, 2025 · View on GitHub
ggcustom is an R package that provides custom themes and color scales
for ggplot2 visualizations, including the VM color palette and theme
as one of the available style options. From ggplot2 4.0.0 onwards the
package configures the organisation palettes through theme palette
entries, so the desired colours are available without overriding global
scale functions.
Installation
To install ggcustom directly from GitHub, use the devtools package:
# Install devtools if not already installed
install.packages("devtools")
# Install ggcustom from GitHub
devtools::install_github("jhuovari/ggcustom")
Overview
The ggcustom package is designed to make it easy to apply consistent
themes and color schemes to ggplot2 visualizations. It includes:
- Custom color palettes for FPB and VM.
- Discrete color and fill scales using those palettes.
- FPB and VM themes for ggplot2 plots with palette defaults wired through the theme.
Usage
Once the package is installed, you can load it with:
library(ggcustom)
Color Scales The package includes custom color scales based on the VM color palette.
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Example dataset
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
# Using the VM color scale
ggplot(dsamp, aes(carat, price, colour = clarity)) +
geom_point() +
scale_colour_vm()
You can also use the fill scale for bar plots or other filled geometries:
ggplot(dsamp, aes(clarity, fill = clarity)) +
geom_bar() +
scale_fill_vm()
VM Theme
The theme_vm() function provides a customized ggplot2 theme based on
theme_bw, with defaults that make use of the VM color palette. When
added to a plot, the theme also registers the VM palette as the default
discrete colour and fill scales via the new theme palette entries in
ggplot2 4.0.0.
# Using the VM theme
p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
p + theme_vm()
Theme Finnish Productivity Board
# Using the fpb theme
p <- txhousing |>
filter(city %in% c("Austin", "Houston", "Dallas", "Arlington")) |>
ggplot(aes(date, inventory, colour = city)) +
geom_line() +
labs(title = "Plot title", subtitle = "Subtitle", caption = "Source:TAMU real estate center")
p + theme_fpb()
Setting Custom Theme and Palette with set_gg()
The set_gg() function allows you to set a custom theme and,
optionally, override palette defaults for your ggplot2 visualizations.
When the palette argument is omitted, the function uses the palette
information already embedded in the supplied theme (for example
theme_vm() adds palette defaults through the ggplot2 4.0.0 theme
palette entries). You can still provide a palette function or ggcustom
palette name to override those defaults when needed. Below is an example
using theme_vm(). For VM there is also the shortcut set_vm().
# Example dataset
data <- data.frame(
category = rep(letters[1:4], each = 3),
value = c(4, 3, 5, 2, 6, 7, 3, 5, 4, 6, 2, 7),
group = rep(1:3, times = 4)
)
# Define a ggplot object
p <- ggplot(data, aes(x = category, y = value, colour = factor(group), group = group)) +
geom_line() +
geom_point()
# Before setting custom theme and palette
p
# Set the VM theme (palette defaults come from the theme itself)
set_gg(theme_vm())
# Plot with VM theme and VM color palette
p
# Optionally, reset to the original theme
unset_gg()
## ggcustom unset.
# Verify that the original theme is restored
p
Additional Palettes and Themes
The package is structured to allow additional color palettes and themes, making it easy to expand with other organization-specific styles.
Examples
# Scatter plot with VM theme and color scale
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(size = 3) +
theme_vm()
# Bar plot with VM fill scale
ggplot(mpg, aes(class, fill = class)) +
geom_bar() +
theme_vm()
Theme helpers
The package includes a few small helpers to simplify adjusting common
ggplot2 theme elements. They wrap
\code{\link[ggplot2]{theme}} calls with convenient defaults.
the_x45()— rotate x-axis tick labels 45° (useful for long category names).the_legend_bot()— move the legend to the bottom.the_title_blank()— blank out selected titles (axis titles, plot title, subtitle, legend title, caption). You can specify which elements to blank with short codes, e.g."xyt"for x-axis, y-axis and plot title.
library(ggplot2)
p <- ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(gear))) +
geom_boxplot() +
labs(title = "Example plot", x = "Cylinders", y = "MPG",
caption = "Data: mtcars")
# Rotate x labels, legend at bottom, blank axis titles
p + the_x45() + the_legend_bot() + the_title_blank("xy")
Contributing
Contributions are welcome! If you’d like to add new color palettes, themes, or functionality, please submit a pull request or open an issue.
License
ggcustom is licensed under the MIT License.