Exploring the package {cols4all} - Colour Palettes for ggplot2 graphics
………………….
ggplot2
Colours
Colour Palette
{cols4all}
Author
Aditya Dahiya
Published
April 16, 2025
Exploring the {cols4all} package
Loading required packages
Code
# Data Import and Wrangling Toolslibrary(tidyverse) # All things tidy# library(sf) # Handling simple features in R# library(terra) # Handling rasters in R# library(tidyterra) # Rasters with ggplot2# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text in ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colourslibrary(seecolor) # To print colourslibrary(cols4all) # The Colour Palette package to explorebts =12# Base Text Sizesysfonts::font_add_google("Saira Condensed", "body_font")showtext::showtext_auto()theme_set(theme_minimal(base_size = bts,base_family ="body_font" ) +theme(text =element_text(colour ="grey20",lineheight =0.3,margin =margin(0,0,0,0, "pt") ) ))# Some basic caption stuff# A base Colourbg_col <-"white"# seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <-"grey30"# seecolor::print_color(text_hil)# Colour for the texttext_col <-"grey20"# seecolor::print_color(text_col)# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_caption <-paste0("**Data**: {geodata} package "," | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)
Data to use: Updated penguins dataset, now included with Base R, version > 4.50
Code
penguins_raw |>as_tibble() |> gt::gt() |> gtExtras::gt_theme_538() |> gt::opt_interactive(page_size_default =5 ) |> gt::tab_options(table.font.size ="small"# Set font size to small )
Exploring the col4all GUI for the palette selector