
okcolors is a collection of aesthetically appealing
color palettes inspired by OK Go music videos for data visualization
with ‘ggplot2’. All palettes support both discrete and continuous
data.
install.packages("okcolors")
library(okcolors)
# dev version:
install.packages('remotes') # if not already installed
# wait for the installation to complete
remotes::install_github('nelsonquesado/okcolors@main')
library(okcolors)The okcolors package provides four
simple functions:
okcolors() – returns a n number of color
hex codes from a named palette.scale_color_okcolors() – adds a custom color scale to a
ggplot2 plot.scale_fill_okcolors() – adds a custom fill scale to a
ggplot2 plot.valid_palettes() - lists available palettes in the
okcolors package.library(ggplot2)
library(okcolors)
ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point(size = 3) +
scale_color_okcolors(discrete = TRUE) # Just add it like any ggplot scale
library(ggplot2)
library(okcolors)
ggplot(mpg, aes(class, fill = class)) +
geom_bar() +
scale_fill_okcolors("skyscrapers", discrete = TRUE) # Again, just add it like any ggplot scale
There are 5 different color palettes, which are described in the next section.
valid_palettes()
[1] "it" "stone" "skyscrapers" "obsession" "moment" Although the palettes are made of 5 basic colors, the package interpolates any number of colors to match the palette.
okcolors('obsession', 12)
[1] "#45924C" "#83A744" "#C1BC3C" "#EFC344" "#ECA07C" "#EA7DB5"
[7] "#EB66B9" "#EF5C87" "#F35155" "#C4536D" "#845A9E" "#4561CF"

library(tidyverse); library(okcolors); library(aopdata); library(sf)
read_landuse('fortaleza', geometry = TRUE) %>%
group_by(id_hex, geometry) %>%
reframe(`Low-income individuals` = P001 * (R003 <= 4) %>% if_else(is.na(.), 0, .),
`Low-complexity job positions` = T002) %>%
pivot_longer(cols = 3:4) %>%
mutate(value = value/sum(value)) %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill = value), color = NA) +
facet_grid(.~name) +
scale_fill_okcolors('it',
transform = 'log',
na.value = okcolors('it', n = 1, direction = 1),
breaks = c(.000001, .0001, .005),
labels = c('0.0001%', '0.01%', '0.5%'),
name = 'Proportion\n',
direction = 1) +
theme_linedraw() +
labs(title = 'Spatial mismatch between low-complexity job positions\nand low-income individuals in Fortaleza, Brazil.') +
theme(legend.position = 'bottom')
Source: Pereira, Rafael H. M. et al. (2022) Distribuição espacial de características sociodemográficas e localização de empregos e serviços públicos das vinte maiores cidades do Brasil. Texto para Discussão 2772. Ipea - Instituto de Pesquisa Econômica Aplicada. http://dx.doi.org/10.38116/td2772


library(tidyverse); library(okcolors)
library(GTFSwizard); library(hrbrthemes)
for_bus_gtfs %>%
get_fleet('by.hour') %>%
ggplot +
geom_line(aes(x = hour, y = fleet, color = service_pattern, group = service_pattern), linewidth = 2) +
scale_color_okcolors('stone',
discrete = TRUE,
direction = -1,
name = 'Service Pattern',
labels = c('Business days', 'Sundays', 'Saturdays')) +
theme_linedraw() +
scale_y_comma(big.mark = '.') +
labs(title = 'Bus fleet variation during the day in Fortaleza, Brazil.',
x = 'Time of the day', y = 'Fleet (veh)') +
theme(legend.position = 'bottom')
Source: Quesado Filho, N. de O., Guimarães, C. G. C. (2024). GTFSwizard: Exploring and Manipulating ‘GTFS’ Files. R package version 1.1.0, https://github.com/OPATP/GTFSwizard.


library(tidyverse); library(okcolors); library(aopdata); library(hrbrthemes)
read_population('all') %>%
mutate(`Proportion of white individuals` = (P002/P001) %>% round(1)) %>%
group_by(`Proportion of white individuals`, name_muni) %>%
reframe(`Average per capita household income` = mean(R001, na.rm = TRUE)) %>%
ggplot +
geom_line(aes(`Proportion of white individuals`,
`Average per capita household income`,
color = `Average per capita household income`)) +
geom_point(aes(`Proportion of white individuals`,
`Average per capita household income`,
color = `Average per capita household income`),
size = 4) +
facet_wrap(name_muni~.) +
scale_color_okcolors('skyscrapers', guide = 'none') +
scale_x_percent(breaks = c(0, 0.2, .4, .6, .8)) +
scale_y_comma(big.mark = '.', prefix = 'R$ ', breaks = c(1000, 3000, 5000)) +
labs(title = 'Average income for different racial contexts') +
theme_linedraw()
Source: Pereira, Rafael H. M. et al. (2022) Distribuição espacial de características sociodemográficas e localização de empregos e serviços públicos das vinte maiores cidades do Brasil. Texto para Discussão 2772. Ipea - Instituto de Pesquisa Econômica Aplicada. http://dx.doi.org/10.38116/td2772


library(tidyverse); library(okcolors)
mpg %>%
ggplot() +
geom_boxplot(aes(x = class, y = hwy, fill = class)) +
labs(title = "Highway MPG by Car Class",
x = "Car Class",
y = "Highway MPG") +
theme_linedraw() +
theme(legend.position = "none") +
scale_fill_okcolors(discrete = TRUE)
Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” Journal of Open Source Software, 4(43), 1686. doi:10.21105/joss.01686 https://doi.org/10.21105/joss.01686.


library(okcolors); library(tidyverse)
diamonds %>%
ggplot(aes(x = cut, fill = clarity)) +
geom_bar(position = "fill") +
labs(title = "Proportion of Clarity Within Diamond Cuts",
x = "Cut",
y = "Proportion",
fill = "Clarity") +
theme_linedraw() +
scale_fill_okcolors('moment', discrete = TRUE, direction = -1)
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
Contributions are welcome! To report a bug, suggest a feature, or contribute code, please use the repository’s Issues.
okcolors mainly relies on ggplot2.
To cite package ‘okcolors’ in publications use:
A BibTeX entry for LaTeX users is
@Manual{quesado.silveira.2025,
title = {okcolors: A Set of Color Palettes Inspired by OK Go Music Videos for ggplot2 in R.},
author = {Nelson de O. {Quesado Filho} and Ana Flávia T. {Silveira}},
year = {2025},
note = {R package version 0.1.2},
url = {https://cran.r-project.org/package=okcolors},
doi = {10.32614/CRAN.package.okcolors}}okcolors is developed by Nelson Quesado and Ana Flávia Teles.