knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = TRUE )
colRoz
is a themed colour palette package by Jacinta Kong & Nicholas Wu. The palettes are based on the colour schemes of Australia. See README for details.
There are two functions of colRoz
:
For this, there are three functions described below. Before that, let's set up this vignette.
library(colRoz) library(ggplot2)
The oz_palettes
function contains the list of palettes available. Individual palettes are grouped by theme in a list. The oz_palettes
variable is a list of these collated lists.
names(oz_palettes) # See all palette themes names(oz_palettes$lizards) # See all lizard palettes
We can call a specific list using subsetting rules for lists.
oz_palettes[["warramaba"]][["whitei"]] # Subset the palette for Warramaba whitei, format: [[theme list]][[palette list]] oz_palettes$warramaba$whitei # does the same as above but using list names
Lists within lists may seem daunting but you'd rarely need to access the palettes individually. It is also easy enough to add your own palettes if you are comfortable with manually editing package functions in R.
The general structure for a set of palettes is:
palette <- list( pal1 = rbind(c(<hex codes>), c(<order of discrete colours>)) )
Two things to note:
The palettes in this package are set as above. The main function is the palette generator. It acts as a housekeeping function to allow R to interpret the desired palette for plotting. The behaviour of this function depends on whether a discrete or continuous palette is desired and the number of colours requested.
If a discrete palette of 3 colours is desired, then the function will chose the subset of 3 colours to be included from the full option of colours in a palette. The chosen order of these colours is hard coded in the list of palette.
Note there is no need to tell
colRoz
what theme the palette you want is in. Type in the palette name andcolRoz
will search the entireoz_palette
list
pal <- colRoz_pal(name = "ngadju", n = 3, type = "discrete") # a palette of only 3 colours ggplot(iris, aes(Petal.Width, Petal.Length , colour=Species)) + geom_point() + scale_colour_manual(values = pal) + theme_classic()
If a continuous palette is desired, then the function will use the function colorRampPalette
in the grDevices
package (included in R) to generate a gradient of colours between the first and last colour in the desired palette.
"continuous"
palettes are generated by default if the type
argument is left blank. In ggplot2
, use the function scale_colour_gradientn
to set the continuous scale.
pal <- colRoz_pal(name = "ngadju", n = 50, type = "continuous") ggplot(iris, aes(Petal.Width, Sepal.Length , colour=Petal.Length)) + geom_point() + scale_colour_gradientn(colours = pal) + theme_classic()
The function to plot the palette is only for graphing. Information is taken about the number of colours to plot from the desired palette and the palette is plotted. The name of the palette is shown.
print_palette(colRoz_pal("c.decresii")) # if empty, all colours are shown print_palette(colRoz_pal("c.decresii", n = 4)) print_palette(colRoz_pal("c.decresii", type = "continuous", n = 30))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.