This package allows users to easily add useful and aesthetic colors schemes in ggplot2. Influenced by the amazing packages nmfspalette and PNWColors. Much of the code for this package is from nmfspalette, written by Christine Stawitz.
adfgcolors is still in active development with new palettes being added. adfgcolors is not endorsed by ADF&G.
You can install the development version from GitHub with:
# install.packages("remotes")
remotes::install_github("justinpriest/adfgcolors")
adfgcolors allows you to quickly specify color palettes in ggplot by
using the functions scale_fill_adfg()
and scale_color_adfg()
, shown
below:
library(adfgcolors)
library(ggplot2)
ggplot(mpg, aes(class, fill = class)) +
geom_bar(color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_adfg(palette = "glacier", discrete = TRUE)
A common need is for plots to be in grayscale, shown here:
library(adfgcolors)
library(ggplot2)
ggplot(mpg, aes(class, fill = class)) +
geom_bar(color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_adfg(palette = "grays_bw", discrete = TRUE)
The color aesthetic is easy to modify:
library(adfgcolors)
library(ggplot2)
ggplot(mpg, aes(x=displ, y = cty, color = cyl)) +
geom_point() +
scale_color_adfg(palette = "alpenglow", discrete = FALSE)
Often, discrete variable plots look best if the exact order of colors
are used (no interpolation), using argument useexact = TRUE
:
library(adfgcolors)
library(ggplot2)
ggplot(mpg, aes(drv, fill = drv)) +
geom_bar(color = "black") +
scale_fill_adfg(palette = "bristolbay", discrete = TRUE, useexact = TRUE)
Colors are generally divided into two categories, discrete and
continuous. Palettes are able to be used as either type, though palettes
described below as discrete display best when plotted for discrete data.
Palettes are shown with hex codes for use in manual plotting, if
desired. To show palettes, use function display_palette()
.
Consider using argument useexact = TRUE
when plotting discrete
variables as it will use the exact order of palettes shown below.
Before plotting, you can show the palette using function
display_palette()
. The arguments for this are the palette name and the
number of colors to display. The associated “hex codes” are shown to
assist users who may want to manually select colors for use in their own
palette.
display_palette("denali", 7)