diff --git a/.Rbuildignore b/.Rbuildignore index 42d854d..63171bf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +^renv$ +^renv\.lock$ ^colourScaleR\.Rproj$ ^\.Rproj\.user$ ^LICENSE\.md$ diff --git a/.gitignore b/.gitignore index 565f2b6..f6b077e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .Rdata .httr-oauth .DS_Store +renv** +.Rprofile diff --git a/R/universal_colour_scaler.R b/R/universal_colour_scaler.R index 74e38c3..0c6e862 100644 --- a/R/universal_colour_scaler.R +++ b/R/universal_colour_scaler.R @@ -268,7 +268,7 @@ universal_colour_scaler <- function( } else if(scale == "log") { breaks <- lseq(from = minx, to = maxx, length_out = n_breaks) } else if(scale == "quantile") { - breaks <- quantile( + breaks <- stats::quantile( x = x, probs = seq(0, 1, length.out = n_breaks), na.rm = TRUE diff --git a/README.md b/README.md new file mode 100644 index 0000000..de2449b --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ + +# colourScaleR + + + + +`colourScaleR` provides a unified interface to [scico](https://github.com/thomasp85/scico), [viridis](https://github.com/sjmgarnier/viridis), & [Color Brewer](https://colorbrewer2.org) for creating colour scales + +## Installation + +You can install the development version of `colourScaleR` from [github](https://github.com/RichardJActon/colourScaleR) with: + +``` r +remotes::install_github("RichardJActon/colourScaleR") +``` + +## Example + +``` r +library(colourScaleR) + +universal_colour_scaler( + rnorm(10), + type = "brewer", + scale = "log", + palette = "RdYlBu", + verbose = TRUE, + n_breaks = 10, + mode = "scaled", + direction = -1 +) +``` + diff --git a/man/lseq.Rd b/man/lseq.Rd new file mode 100644 index 0000000..785dd5c --- /dev/null +++ b/man/lseq.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/universal_colour_scaler.R +\name{lseq} +\alias{lseq} +\title{lseq} +\usage{ +lseq(from = 1, to = 1e+05, length_out = 6) +} +\arguments{ +\item{from}{start} + +\item{to}{end} + +\item{length_out}{number of increments} +} +\description{ +logarithmic sequence +} diff --git a/man/range_check.Rd b/man/range_check.Rd new file mode 100644 index 0000000..d0499b3 --- /dev/null +++ b/man/range_check.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/universal_colour_scaler.R +\name{range_check} +\alias{range_check} +\title{range_check} +\usage{ +range_check(min, max, var) +} +\arguments{ +\item{min}{min} + +\item{max}{max} + +\item{var}{variable name} +} +\description{ +check if a variable with within a range and error if it is not +} diff --git a/man/universal_colour_scaler.Rd b/man/universal_colour_scaler.Rd new file mode 100644 index 0000000..b85519b --- /dev/null +++ b/man/universal_colour_scaler.Rd @@ -0,0 +1,86 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/universal_colour_scaler.R +\name{universal_colour_scaler} +\alias{universal_colour_scaler} +\title{universal_colour_scaler} +\usage{ +universal_colour_scaler( + x, + scale = "linear", + type = "scico", + palette = "bilbao", + n_breaks = 5, + direction = 1, + alpha = 1, + begin = 0, + end = 1, + mode = "scaled", + verbose = FALSE +) +} +\arguments{ +\item{x}{The values for which you wish to generate a colour scale +(a vector or matrix of numeric type)} + +\item{scale}{The type of colour scale you would like to generate. +"linear", (the default), "log", "quantile" or a custom numeric vector} + +\item{type}{the type of palette you would like to use. +"scico" (the default), "viridis", "brewer" or "custom". +if you specify custom} + +\item{palette}{The name of one of the 68 colour palettes from scico, +viridis (defaults to "bilbao" from scico) +\itemize{ +\item scico palettes: +"acton", "bamako", "batlow", "berlin", "bilbao", "broc", "brocO", "buda", +"cork", "corkO", "davos", "devon", "grayC", "hawaii", "imola", "lajolla", +"lapaz", "lisbon", "nuuk", "oleron", "oslo", "roma", "romaO", "tofino", +"tokyo", "turku", "vik", "vikO" +\item viridis palettes: +"viridis", "inferno", "magma", "plasma", "cividis" +\item brewer palettes: +"BrBG", "PiYG", "PRGn", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", +"Spectral", "Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", +"Set2", "Set3", "Blues", "BuGn", "BuPu", "GnBu", "Greens", "Greys", +"Oranges", "OrRd", "PuBu", "PuBuGn", "PuRd", "Purples", "RdPu", "Reds", +"YlGn", "YlGnBu", "YlOrBr", "YlOrRd" +}} + +\item{n_breaks}{the number of colour breaks to use from a palette +this will be the number of increments in the linear scale, +the number of natural log spaced steps in a log scale or the number of +evenly separated quantiles in a qualtile scale} + +\item{direction}{defaults to 1, -1 inverts the colour scale} + +\item{alpha}{transparency (a value between 0 and 1, defaults to 1)} + +\item{begin}{The beggining to the interval within the palette to sample +colours from (defaults to 0) +NB acts a little differently for brewer's discrete palettes +it rounds to the nearest whole number as a proportion of the number of +breaks you specified and truncates the palette there.} + +\item{end}{The end to the interval within the palette to sample +colours from (defaults to 1)} + +\item{mode}{the type of output you get is set with mode +"scaled" (the default) outputs a vector the same length as x with +appropriately scaled colour values. +"closure" returns a function to generate new scales based on x +e.g. subsets of x you want to visualize using the same global colour scale +"palette" a vector of the hex codes the names of which are the breaks} + +\item{verbose}{verbose mode prints a message with the colours and breaks +as well as plotting a grid of the colours in the palette} +} +\description{ +A function for generating colour scales using these palettes: +\itemize{ +\item viridis +\item scico +\item colour brewer +\item custom hex code based +} +}