Title: | Easily Create, View and Use Monochrome Colour Palettes |
---|---|
Description: | Generate a monochrome palette from a starting colour for a specified number of colours. The package can also be used to display colour palettes in the plot window, with or without hex codes and colour labels. |
Authors: | Cara Thompson [aut, cre] |
Maintainer: | Cara Thompson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-31 23:16:20 UTC |
Source: | https://github.com/cararthompson/monochromer |
Checks colour variables are either RGB values, hex colour codes or a recognised colour name and converts to rgb (helper funct)
check_colour_return_rgb(colour, colour_variable_name)
check_colour_return_rgb(colour, colour_variable_name)
colour |
The colour string / rgb vector to check |
colour_variable_name |
The name of the variable, for readability of error messages |
An error message if the colour value can't be interpreted
check_colour_return_rgb("White", "test_colour") ## Not run: check_colour_return_rgb("foo", "test_colour")
check_colour_return_rgb("White", "test_colour") ## Not run: check_colour_return_rgb("foo", "test_colour")
This function allows users generate a monochrome colour palette
containing any number of colours, starting from the colour they specify. The modification
parameter can be set to make the palette go darker, lighter, or both
ways from the starting colour. The function also allows users to create
a palette that goes from one colour to another, by providing a blend_colour
.
generate_palette( colour, modification, n_colours, blend_colour = NULL, view_palette = FALSE, view_labels = TRUE, ... )
generate_palette( colour, modification, n_colours, blend_colour = NULL, view_palette = FALSE, view_labels = TRUE, ... )
colour |
The starting colour for the palette, which must be either be a recognised colour name (e.g. "white"), a hex colour code (e.g. "#ffffff") or vector of length 3 (red value, green value, blue value, e.g. c(15, 75, 99)), with all values between 0 and 255. |
modification |
One of the following: "go_darker", "go_lighter", "go_both_ways", or "blend".
If a |
n_colours |
Number of colours (levels) required in the palette |
blend_colour |
Optional. Can be either be a recognised colour name (e.g. "white"), a hex colour code (e.g. "#ffffff") or vector of length 3 (red value, green value, blue value, e.g. c(15, 75, 99)), with all values between 0 and 255. |
view_palette |
Logical. |
view_labels |
Logical. If view_palette is set to TRUE, view_labels = FALSE determines whether or not the hex colour codes are shown on the palette displayed in the plot window. |
... |
Allows for US spelling of color/colour. |
A vector of hex colour codes making up the generated palette
generate_palette("red", modification = "go_lighter", n_colours = 5, view_palette = TRUE, view_labels = TRUE) generate_palette(c(15, 75, 99), modification = "go_both_ways", n_colours = 12, view_palette = TRUE, view_labels = FALSE) generate_palette("red", blend_colour = "blue", n_colours = 6, view_palette = TRUE)
generate_palette("red", modification = "go_lighter", n_colours = 5, view_palette = TRUE, view_labels = TRUE) generate_palette(c(15, 75, 99), modification = "go_both_ways", n_colours = 12, view_palette = TRUE, view_labels = FALSE) generate_palette("red", blend_colour = "blue", n_colours = 6, view_palette = TRUE)
Converts Hex codes values to RGB vectors
hex_to_rgb(x)
hex_to_rgb(x)
x |
A hex colour code |
A corresponding matrix of red, blue and green values
hex_to_rgb("purple") hex_to_rgb("#fafafa")
hex_to_rgb("purple") hex_to_rgb("#fafafa")
Converts RGB values to hex colour code
rgb_to_hex(x)
rgb_to_hex(x)
x |
A matrix of red, blue and green values |
A corresponding hex colour code
temp_rgb_matrix <- rgba_to_rgb(c(52, 46, 39, 0.8)) rgb_to_hex(temp_rgb_matrix)
temp_rgb_matrix <- rgba_to_rgb(c(52, 46, 39, 0.8)) rgb_to_hex(temp_rgb_matrix)
rgba_to_hex
rgba_to_hex(colour_rgba, background_colour = "#ffffff", ...)
rgba_to_hex(colour_rgba, background_colour = "#ffffff", ...)
colour_rgba |
A vector of length 4: c(red value, green value, blue value, alpha). All colour values must be between 0 and 255. Alpha must be between 0 and 1. |
background_colour |
Defaults to white. Users can specify a different colour to get
the hex code for their original colour blended with a specified background colour.
|
... |
Allows for US spelling of color/colour. |
Returns the corresponding hex colour code
rgba_to_hex(c(52, 46, 39, 0.8)) rgba_to_hex(c(52, 46, 39, 0.8), "blue") rgba_to_hex(c(52, 46, 39, 0.8), "#032cfc")
rgba_to_hex(c(52, 46, 39, 0.8)) rgba_to_hex(c(52, 46, 39, 0.8), "blue") rgba_to_hex(c(52, 46, 39, 0.8), "#032cfc")
Converts RGBA to RGB (helper function)
rgba_to_rgb(colour_rgba, background_colour = "#ffffff", ...)
rgba_to_rgb(colour_rgba, background_colour = "#ffffff", ...)
colour_rgba |
A vector of length 4: c(red value, green value, blue value, alpha). All colour values must be between 0 and 255. Alpha must be between 0 and 1. |
background_colour |
Defaults to white. Users can specify a different colour to get
the hex code for their original colour blended with a specified background colour.
|
... |
Allows for US spelling of color/colour. |
A matrix of red, green and blue values
rgba_to_rgb(c(52, 46, 39, 0.8)) rgba_to_rgb(c(52, 46, 39, 0.8), "blue") rgba_to_rgb(c(52, 46, 39, 0.8), "#032cfc")
rgba_to_rgb(c(52, 46, 39, 0.8)) rgba_to_rgb(c(52, 46, 39, 0.8), "blue") rgba_to_rgb(c(52, 46, 39, 0.8), "#032cfc")
Easy way to view the created palette
view_palette(monochrome_palette, view_labels = TRUE)
view_palette(monochrome_palette, view_labels = TRUE)
monochrome_palette |
Vector of hex colour codes, or a |
view_labels |
Logical. If |
A plot showing all the colours in the palette on the same row
view_palette(c("#464E69", "#8C90A1", "#D1D2D9")) view_palette(c("unripe" = "#89973d", "ripe" = "#e8b92f", "overripe" = "#a45e41")) view_palette(generate_palette("pink", "go_darker", n_colours = 3))
view_palette(c("#464E69", "#8C90A1", "#D1D2D9")) view_palette(c("unripe" = "#89973d", "ripe" = "#e8b92f", "overripe" = "#a45e41")) view_palette(generate_palette("pink", "go_darker", n_colours = 3))