Skip to contents

Overview

biopalette provides color palettes for biomedical visualization, each sourced from a real image. This guide covers the core workflow: browsing, retrieving, previewing, and using palettes in plots.

Installation

pak::pkg_install("evanbio/biopalette")

Browse Available Palettes

list_palettes() returns a data frame of all available palettes with their name, type, and number of colors. palette_gallery() renders a visual overview.

Retrieve Colors

# Full palette
get_palette("babel")

# First n colors
get_palette("babel", n = 5)

# Specify type for disambiguation
get_palette("walter_white", type = "diverging")

The returned value is a named character vector of HEX codes, ready to pass to any plotting function.

Preview a Palette

preview_palette("gene_red")
preview_palette("babel", plot_type = "rect")
preview_palette("three_body", plot_type = "circle")

Use in ggplot2

library(ggplot2)

cols <- get_palette("three_body")

ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point(size = 2) +
  scale_color_manual(values = cols)

For continuous scales, pass colors directly to scale_fill_gradientn() or scale_color_gradientn():

cols <- get_palette("walter_white")

ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
  geom_tile() +
  scale_fill_gradientn(colors = cols)

Color Utilities

hex2rgb("#1688A7")
rgb2hex(22, 136, 167)

Function Reference

Function Purpose
list_palettes() Data frame of all available palettes
palette_gallery() Visual gallery of all palettes
get_palette() Retrieve colors by name, type, and size
preview_palette() Render color swatches
create_palette() Add a new palette
compile_palettes() Compile all JSONs into a named list
remove_palette() Remove a palette by name
hex2rgb() HEX to RGB
rgb2hex() RGB to HEX

Getting Help