Palettes based on the colour schemes for IDEM, IDDU, ACEFA, and The Kids Research Institute Australia
- provides functions for colour palettes based on IDEM, IDDU, ACEFA, and The Kids, and
- provides a
scale
function that allows the use of these or any color palette withggplot2
continuous scales.
For a palette of n
colours, call: idem(n)
,iddu(n)
, acefa(n)
, or
thekids(n)
A wider range of slightly differing palettes available via idpalette
,
see ?idpal
for details.
ggplot2
does not like it when you specify an arbitrary vector of
colours to a continuous scale. scale_id_continous
allows you to pass
any vector of colours, either as an idpalette
palette, another
palette, or a character vector of whatever god-awful unicorn vomitus
suits your whimsy of the moment.
You can install the development version of idpalette
from
GitHub with:
# install.packages("devtools")
devtools::install_github("idem-lab/idpalette")
Python version of idpalette
by Rob Moss:
https://github.com/robmoss/idpalette
library(idpalette)
idem() # alias for idpalette("idem")
idpalette("idem_official")
iddu() # alias for idpalette("iddu")
idpalette("iddu_official")
acefa() # alias for idpalette("acefa")
idpalette("acefa_official")
thekids() # alias for idpalette("thekids")
idpalette("thekids_official")
idpalette("thekids_diverging")
As many or as few colours as you want, forwards or backwards.
idpalette("iddu", 20)
idpalette("acefa", 2)
idem(10, rev = TRUE)
Sometimes ggplot2
won’t play nicely being fed a vector of values for
vector of colours to be used in continuous scales.
scale_id_continuous
allows idpalette
or any arbitrary vector of
colours to be converted into a continuous palette:
library(ggplot2)
ggplot(mtcars) +
geom_point(
aes(
x = disp,
y = hp,
colour = qsec
),
size = 5
) +
# usual approach to alter colours:
# scale_fill_continuous(
# palette = iddu()
# ) # but not allowed: Cannot convert `x` to a continuous palette.
# instead we use `scale_id_continuous`:
scale_id_continuous(
cols = iddu(),
aesthetics = "colour"
)
With your own wonderful colour scheme
my_wonderful_colour_scheme <- c("brown4", "magenta", "grey80", "salmon", "gold")
ggplot(mtcars) +
geom_point(
aes(
x = disp,
y = hp,
colour = qsec
),
size = 5
) +
scale_id_continuous(
cols = my_wonderful_colour_scheme,
aesthetics = "colour"
)
library(ggplot2)
ggplot(
faithfuld,
aes(waiting, eruptions)
) +
geom_raster(
aes(fill = density)
) +
scale_fill_gradientn(
colours = idpalette("iddu", 100)
)
ggplot(mpg) +
geom_bar(
aes(
x = trans,
fill = class
)
) +
scale_fill_manual(values = idem()) +
theme_bw()
With terra
:
library(sdmtools)
library(terra)
#> terra 1.8.60
r <- example_raster(seed = 20240802)
par(mfcol = c(1, 2))
plot(
r,
col = thekids(100)
)
plot(
r,
col = thekids(100, rev = TRUE)
)