diff --git a/DESCRIPTION b/DESCRIPTION index 34279fe..09684ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: colourvalues Type: Package Title: Assigns Colours to Values Version: 0.2.1 -Date: 2018-11-07 +Date: 2018-12-18 Authors@R: c( person("David", "Cooley", ,"dcooley@symbolix.com.au", role = c("aut", "cre")) ) diff --git a/NAMESPACE b/NAMESPACE index 94bcd27..4ad3fcb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -29,15 +29,6 @@ S3method(convert_colour,numeric) S3method(palette_check,character) S3method(palette_check,default) S3method(palette_check,matrix) -export(blue2green) -export(blue2red) -export(blue2yellow) -export(blues) -export(brbg) -export(bugn) -export(bupu) -export(cividis) -export(cm) export(color_palettes) export(color_values) export(color_values_rgb) @@ -48,49 +39,6 @@ export(convert_color) export(convert_colors) export(convert_colour) export(convert_colours) -export(cyan2yellow) -export(diverge_hcl) -export(diverge_hsv) -export(gnbu) -export(green2red) -export(greens) -export(greys) -export(heat) -export(heat_hcl) -export(inferno) -export(magenta2green) -export(magma) -export(matlab_like) -export(matlab_like2) -export(oranges) -export(orrd) -export(piyg) -export(plasma) -export(prgn) -export(pubu) -export(pubugn) -export(puor) -export(purd) -export(purples) -export(rainbow) -export(rainbow_hcl) -export(rdbu) -export(rdgy) -export(rdpu) -export(rdylbu) -export(rdylgn) -export(reds) -export(sequential_hcl) export(show_colours) -export(spectral) -export(terrain) -export(terrain_hcl) -export(topo) -export(viridis) -export(ygobb) -export(ylgn) -export(ylgnbu) -export(ylorbr) -export(ylorrd) importFrom(Rcpp,sourceCpp) useDynLib(colourvalues, .registration = TRUE) diff --git a/R/palettes.R b/R/palettes.R index 2b35802..0b9e358 100644 --- a/R/palettes.R +++ b/R/palettes.R @@ -63,35 +63,30 @@ show_colours <- function( colours = colour_palettes() ) { #' #' Data frame of the viridis palette #' -#' @export viridis <- function() rcpp_viridis() #' Inferno #' #' Data frame of the inferno palette #' -#' @export inferno <- function() rcpp_inferno() #' Plasma #' #' Data frame of the plasma palette #' -#' @export plasma <- function() rcpp_plasma() #' Magma #' #' Data frame of the magma palette #' -#' @export magma <- function() rcpp_magma() #' Cividis #' #' Data frame of the cividis palette #' -#' @export cividis <- function() rcpp_cividis() @@ -99,325 +94,281 @@ cividis <- function() rcpp_cividis() #' #' Data frame of the terrain palette #' -#' @export terrain <- function() rcpp_terrain() #' Topo #' #' Data Frame of the topo palette #' -#' @export topo <- function() rcpp_topo() #' Heat #' #' Data Frame of the heat palette #' -#' @export heat <- function() rcpp_heat() #' Ylorrd #' #' Data Frame of the ylorrd palette #' -#' @export ylorrd <- function() rcpp_ylorrd() #' Ylorbr #' #' Data Frame of the ylorbr palette #' -#' @export ylorbr <- function() rcpp_ylorbr() #' Ylgnbu #' #' Data Frame of the ylgnbu palette #' -#' @export ylgnbu <- function() rcpp_ylgnbu() #' Ylgn #' #' Data Frame of the ylgn palette #' -#' @export ylgn <- function() rcpp_ylgn() #' Reds #' #' Data Frame of the reds palette #' -#' @export reds <- function() rcpp_reds() #' Rdpu #' #' Data Frame of the rdpu palette #' -#' @export rdpu <- function() rcpp_rdpu() #' Purples #' #' Data Frame of the purples palette #' -#' @export purples <- function() rcpp_purples() #' Purd #' #' Data Frame of the purd palette #' -#' @export purd <- function() rcpp_purd() #' Pubugn #' #' Data Frame of the pubugn palette #' -#' @export pubugn <- function() rcpp_pubugn() #' Pubu #' #' Data Frame of the pubu palette #' -#' @export pubu <- function() rcpp_pubu() #' Orrd #' #' Data Frame of the orrd palette #' -#' @export orrd <- function() rcpp_orrd() #' Oranges #' #' Data Frame of the oranges palette #' -#' @export oranges <- function() rcpp_oranges() #' Greys #' #' Data Frame of the greys palette #' -#' @export greys <- function() rcpp_greys() #' Greens #' #' Data Frame of the greens palette #' -#' @export greens <- function() rcpp_greens() #' Gnbu #' #' Data Frame of the gnbu palette #' -#' @export gnbu <- function() rcpp_gnbu() #' Bupu #' #' Data Frame of the bupu palette #' -#' @export bupu <- function() rcpp_bupu() #' Bugn #' #' Data Frame of the bugn palette #' -#' @export bugn <- function() rcpp_bugn() #' Blues #' #' Data Frame of the blues palette #' -#' @export blues <- function() rcpp_blues() #' Spectral #' #' Data Frame of the spectral palette #' -#' @export spectral <- function() rcpp_spectral() #' Rdylgn #' #' Data Frame of the rdylgn palette #' -#' @export rdylgn <- function() rcpp_rdylgn() #' Rdylbu #' #' Data Frame of the rdylbu palette #' -#' @export rdylbu <- function() rcpp_rdylbu() #' Rdgy #' #' Data Frame of the rdgy palette #' -#' @export rdgy <- function() rcpp_rdgy() #' Rdbu #' #' Data Frame of the rdbu palette #' -#' @export rdbu <- function() rcpp_rdbu() #' Puor #' #' Data Frame of the puor palette #' -#' @export puor <- function() rcpp_puor() #' Prgn #' #' Data Frame of the prgn palette #' -#' @export prgn <- function() rcpp_prgn() #' Piyg #' #' Data Frame of the piyg palette #' -#' @export piyg <- function() rcpp_piyg() #' Brbg #' #' Data Frame of the brbg palette #' -#' @export brbg <- function() rcpp_brbg() #' Cm #' #' Data Frame of the cm palette #' -#' @export cm <- function() rcpp_cm() + #' Rainbow #' #' Data Frame of the rainbow palette #' -#' @export rainbow <- function() rcpp_rainbow() + #' Ygobb #' #' Data Frame of the ygobb palette #' -#' @export ygobb <- function() rcpp_ygobb() #' Matlab_like2 #' #' Data Frame of the matlab_like2 palette #' -#' @export matlab_like2 <- function() rcpp_matlab_like2() #' Matlab_like #' #' Data Frame of the matlab_like palette #' -#' @export matlab_like <- function() rcpp_matlab_like() #' Magenta2green #' #' Data Frame of the magenta2green palette #' -#' @export magenta2green <- function() rcpp_magenta2green() #' Cyan2yellow #' #' Data Frame of the cyan2yellow palette #' -#' @export cyan2yellow <- function() rcpp_cyan2yellow() #' Blue2yellow #' #' Data Frame of the blue2yellow palette #' -#' @export blue2yellow <- function() rcpp_blue2yellow() #' Green2red #' #' Data Frame of the green2red palette #' -#' @export green2red <- function() rcpp_green2red() #' Blue2green #' #' Data Frame of the blue2green palette #' -#' @export blue2green <- function() rcpp_blue2green() #' Blue2red #' #' Data Frame of the blue2red palette #' -#' @export blue2red <- function() rcpp_blue2red() #' Diverge_hcl #' #' Data Frame of the diverge_hcl palette #' -#' @export diverge_hcl <- function() rcpp_diverge_hcl() #' Diverge_hsv #' #' Data Frame of the diverge_hsv palette #' -#' @export diverge_hsv <- function() rcpp_diverge_hsv() #' Terrain_hcl #' #' Data Frame of the terrain_hcl palette #' -#' @export terrain_hcl <- function() rcpp_terrain_hcl() #' Heat_hcl #' #' Data Frame of the heat_hcl palette #' -#' @export heat_hcl <- function() rcpp_heat_hcl() #' Sequential_hcl #' #' Data Frame of the sequential_hcl palette #' -#' @export sequential_hcl <- function() rcpp_sequential_hcl() #' Rainbow_hcl #' #' Data Frame of the rainbow_hcl palette #' -#' @export rainbow_hcl <- function() rcpp_rainbow_hcl() + diff --git a/README.Rmd b/README.Rmd index fa84fd1..5f8304f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -108,9 +108,12 @@ Of course! #### 256 numbers mapped to a colour ```{r} +bar_plot <- function(df) { + barplot( height = df[["a"]], col = df[["col"]], border = NA, space = 0, yaxt = 'n') +} df <- data.frame(a = 10, x = 1:256) df$col <- colour_values(df$x, palette = "viridis") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` #### 5000 numbers on a non-linear scale @@ -118,7 +121,7 @@ barplot(height = df$a, col = df$col, border = NA, space = 0) ```{r} df <- data.frame(a = 10, x = c((1:5000)**3)) df$col <- colour_values(df$x, palette = "viridis") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` #### 1000 random numbers @@ -126,14 +129,14 @@ barplot(height = df$a, col = df$col, border = NA, space = 0) ```{r} df <- data.frame(a = 10, x = rnorm(n = 1000)) df$col <- colour_values(df$x, palette = "inferno") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` Eurgh! ```{r} df <- df[with(df, order(x)), ] -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` That's better! @@ -150,7 +153,7 @@ n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -162,7 +165,7 @@ Yep. Either supply a single alpha value for all the colours ## single alpha value for all colours df <- data.frame(a = 10, x = 1:255) df$col <- colour_values(df$x, alpha = 50) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` Or use a vector of values the same length as `x` @@ -170,7 +173,7 @@ Or use a vector of values the same length as `x` ```{r} df <- data.frame(a = 10, x = 1:300, y = rep(c(1:50, 50:1), 3) ) df$col <- colour_values(df$x, alpha = df$y) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -183,7 +186,7 @@ m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) m <- cbind(m, seq(0, 255, length.out = 100)) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` ## Some of my plotting functions don't support alpha, can I exclude it? @@ -241,7 +244,7 @@ library(ggplot2) library(scales) library(viridisLite) -n <- 1e7 +n <- 1e6 df <- data.frame(x = rnorm(n = n)) m <- microbenchmark( @@ -263,7 +266,7 @@ library(ggplot2) library(scales) library(viridisLite) -n <- 1e6 +n <- 5e5 x <- sample(x = letters, size = n, replace = TRUE) df <- data.frame(x = x) diff --git a/README.md b/README.md index da2b82e..c1f3667 100644 --- a/README.md +++ b/README.md @@ -109,9 +109,12 @@ Of course\! #### 256 numbers mapped to a colour ``` r +bar_plot <- function(df) { + barplot( height = df[["a"]], col = df[["col"]], border = NA, space = 0, yaxt = 'n') +} df <- data.frame(a = 10, x = 1:256) df$col <- colour_values(df$x, palette = "viridis") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -121,7 +124,7 @@ barplot(height = df$a, col = df$col, border = NA, space = 0) ``` r df <- data.frame(a = 10, x = c((1:5000)**3)) df$col <- colour_values(df$x, palette = "viridis") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -131,7 +134,7 @@ barplot(height = df$a, col = df$col, border = NA, space = 0) ``` r df <- data.frame(a = 10, x = rnorm(n = 1000)) df$col <- colour_values(df$x, palette = "inferno") -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -140,7 +143,7 @@ Eurgh\! ``` r df <- df[with(df, order(x)), ] -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -159,7 +162,7 @@ n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -172,7 +175,7 @@ Yep. Either supply a single alpha value for all the colours ## single alpha value for all colours df <- data.frame(a = 10, x = 1:255) df$col <- colour_values(df$x, alpha = 50) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -182,7 +185,7 @@ Or use a vector of values the same length as `x` ``` r df <- data.frame(a = 10, x = 1:300, y = rep(c(1:50, 50:1), 3) ) df$col <- colour_values(df$x, alpha = df$y) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -196,7 +199,7 @@ m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) m <- cbind(m, seq(0, 255, length.out = 100)) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) -barplot(height = df$a, col = df$col, border = NA, space = 0) +bar_plot( df ) ``` @@ -241,11 +244,11 @@ summary ``` r colour_values(rnorm(n = 10), n_summaries = 3, digits = 2) # $colours -# [1] "#20918CFF" "#98D83EFF" "#26838EFF" "#B3DD2CFF" "#B3DD2DFF" -# [6] "#2C738EFF" "#FDE725FF" "#355E8DFF" "#B7DE2AFF" "#440154FF" +# [1] "#49C16EFF" "#31668EFF" "#20938CFF" "#54C568FF" "#FDE725FF" +# [6] "#440154FF" "#F6E61FFF" "#47C06FFF" "#1F998AFF" "#38578CFF" # # $summary_values -# [1] "-2.76" "-1.17" "0.41" +# [1] "-1.55" "0.11" "1.77" # # $summary_colours # [1] "#440154FF" "#21908CFF" "#FDE725FF" @@ -295,27 +298,26 @@ values, and their associated colours ``` r colour_values(sample(letters, size = 50, replace = T), summary = T) # $colours -# [1] "#440154FF" "#31688EFF" "#C7E020FF" "#481F71FF" "#FDE725FF" -# [6] "#472D7BFF" "#472D7BFF" "#3B528BFF" "#471163FF" "#E3E418FF" -# [11] "#8FD744FF" "#E3E418FF" "#472D7BFF" "#2C728EFF" "#20A486FF" -# [16] "#ABDC32FF" "#2C728EFF" "#24868EFF" "#35B779FF" "#28AE80FF" -# [21] "#ABDC32FF" "#E3E418FF" "#24868EFF" "#31688EFF" "#47C06FFF" -# [26] "#20A486FF" "#404688FF" "#24868EFF" "#28AE80FF" "#443A83FF" -# [31] "#47C06FFF" "#3B528BFF" "#75D054FF" "#404688FF" "#404688FF" -# [36] "#481F71FF" "#287C8EFF" "#20A486FF" "#5DC963FF" "#ABDC32FF" -# [41] "#1F9A8AFF" "#443A83FF" "#355D8DFF" "#28AE80FF" "#E3E418FF" -# [46] "#28AE80FF" "#8FD744FF" "#21908CFF" "#28AE80FF" "#8FD744FF" +# [1] "#481567FF" "#453781FF" "#73D055FF" "#404788FF" "#29AF7FFF" +# [6] "#238A8DFF" "#29AF7FFF" "#1F968BFF" "#95D840FF" "#482677FF" +# [11] "#3CBB75FF" "#FDE725FF" "#238A8DFF" "#39568CFF" "#95D840FF" +# [16] "#39568CFF" "#DCE319FF" "#73D055FF" "#440154FF" "#FDE725FF" +# [21] "#238A8DFF" "#1F968BFF" "#B8DE29FF" "#39568CFF" "#95D840FF" +# [26] "#440154FF" "#95D840FF" "#33638DFF" "#404788FF" "#453781FF" +# [31] "#287D8EFF" "#33638DFF" "#FDE725FF" "#2D708EFF" "#55C667FF" +# [36] "#2D708EFF" "#404788FF" "#482677FF" "#2D708EFF" "#B8DE29FF" +# [41] "#95D840FF" "#1F968BFF" "#20A387FF" "#20A387FF" "#482677FF" +# [46] "#287D8EFF" "#453781FF" "#404788FF" "#39568CFF" "#20A387FF" # # $summary_values -# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "m" "n" "o" "p" "q" "r" -# [18] "s" "t" "u" "v" "w" "x" "y" "z" +# [1] "a" "b" "e" "f" "g" "h" "i" "j" "l" "m" "n" "o" "q" "r" "s" "u" "w" +# [18] "x" "y" "z" # # $summary_colours -# [1] "#440154FF" "#471163FF" "#481F71FF" "#472D7BFF" "#443A83FF" -# [6] "#404688FF" "#3B528BFF" "#355D8DFF" "#31688EFF" "#2C728EFF" -# [11] "#287C8EFF" "#24868EFF" "#21908CFF" "#1F9A8AFF" "#20A486FF" -# [16] "#28AE80FF" "#35B779FF" "#47C06FFF" "#5DC963FF" "#75D054FF" -# [21] "#8FD744FF" "#ABDC32FF" "#C7E020FF" "#E3E418FF" "#FDE725FF" +# [1] "#440154FF" "#481567FF" "#482677FF" "#453781FF" "#404788FF" +# [6] "#39568CFF" "#33638DFF" "#2D708EFF" "#287D8EFF" "#238A8DFF" +# [11] "#1F968BFF" "#20A387FF" "#29AF7FFF" "#3CBB75FF" "#55C667FF" +# [16] "#73D055FF" "#95D840FF" "#B8DE29FF" "#DCE319FF" "#FDE725FF" ``` ----- @@ -329,13 +331,8 @@ library(microbenchmark) library(ggplot2) library(scales) library(viridisLite) -# -# Attaching package: 'viridisLite' -# The following objects are masked from 'package:colourvalues': -# -# cividis, inferno, magma, plasma, viridis -n <- 1e7 +n <- 1e6 df <- data.frame(x = rnorm(n = n)) m <- microbenchmark( @@ -344,10 +341,13 @@ m <- microbenchmark( times = 25 ) m -# Unit: seconds -# expr min lq mean median uq max neval -# colourvalues 1.617392 1.650307 1.707740 1.688513 1.757597 1.866051 25 -# scales 2.772918 2.889632 2.958089 2.922623 3.016068 3.344712 25 +# Unit: milliseconds +# expr min lq mean median uq max +# colourvalues 413.7846 465.2459 667.549 533.3406 775.9402 1768.377 +# scales 865.6236 985.3206 1476.348 1357.1543 2078.2787 2857.309 +# neval +# 25 +# 25 autoplot(m) # Coordinate system already present. Adding new coordinate system, which will replace the existing one. @@ -363,7 +363,7 @@ library(ggplot2) library(scales) library(viridisLite) -n <- 1e6 +n <- 5e5 x <- sample(x = letters, size = n, replace = TRUE) df <- data.frame(x = x) @@ -375,8 +375,8 @@ m <- microbenchmark( m # Unit: milliseconds # expr min lq mean median uq max neval -# colourvalues 183.6266 191.3288 196.3723 192.1881 192.8737 304.3512 25 -# scales 288.9669 311.4043 320.7450 313.7732 318.0472 378.1733 25 +# colourvalues 219.6011 251.1079 281.4803 257.8884 268.8997 457.7094 25 +# scales 392.0473 418.4014 536.5625 453.4664 566.0392 999.5088 25 autoplot(m) # Coordinate system already present. Adding new coordinate system, which will replace the existing one. diff --git a/man/figures/README-unnamed-chunk-10-1.png b/man/figures/README-unnamed-chunk-10-1.png index 20aa5c6..dc3f851 100644 Binary files a/man/figures/README-unnamed-chunk-10-1.png and b/man/figures/README-unnamed-chunk-10-1.png differ diff --git a/man/figures/README-unnamed-chunk-16-1.png b/man/figures/README-unnamed-chunk-16-1.png index 9460f5e..c046119 100644 Binary files a/man/figures/README-unnamed-chunk-16-1.png and b/man/figures/README-unnamed-chunk-16-1.png differ diff --git a/man/figures/README-unnamed-chunk-17-1.png b/man/figures/README-unnamed-chunk-17-1.png index 1304574..3076c28 100644 Binary files a/man/figures/README-unnamed-chunk-17-1.png and b/man/figures/README-unnamed-chunk-17-1.png differ diff --git a/man/figures/README-unnamed-chunk-3-1.png b/man/figures/README-unnamed-chunk-3-1.png index ade2758..f288b9e 100644 Binary files a/man/figures/README-unnamed-chunk-3-1.png and b/man/figures/README-unnamed-chunk-3-1.png differ diff --git a/man/figures/README-unnamed-chunk-4-1.png b/man/figures/README-unnamed-chunk-4-1.png index ed329fe..0bdd830 100644 Binary files a/man/figures/README-unnamed-chunk-4-1.png and b/man/figures/README-unnamed-chunk-4-1.png differ diff --git a/man/figures/README-unnamed-chunk-5-1.png b/man/figures/README-unnamed-chunk-5-1.png index bc95c11..7bd7338 100644 Binary files a/man/figures/README-unnamed-chunk-5-1.png and b/man/figures/README-unnamed-chunk-5-1.png differ diff --git a/man/figures/README-unnamed-chunk-6-1.png b/man/figures/README-unnamed-chunk-6-1.png index 82557ca..c58da52 100644 Binary files a/man/figures/README-unnamed-chunk-6-1.png and b/man/figures/README-unnamed-chunk-6-1.png differ diff --git a/man/figures/README-unnamed-chunk-7-1.png b/man/figures/README-unnamed-chunk-7-1.png index 526c9dc..b557ffa 100644 Binary files a/man/figures/README-unnamed-chunk-7-1.png and b/man/figures/README-unnamed-chunk-7-1.png differ diff --git a/man/figures/README-unnamed-chunk-8-1.png b/man/figures/README-unnamed-chunk-8-1.png index 25fd8d3..cb73b5d 100644 Binary files a/man/figures/README-unnamed-chunk-8-1.png and b/man/figures/README-unnamed-chunk-8-1.png differ diff --git a/man/figures/README-unnamed-chunk-9-1.png b/man/figures/README-unnamed-chunk-9-1.png index ddb71e8..84d4139 100644 Binary files a/man/figures/README-unnamed-chunk-9-1.png and b/man/figures/README-unnamed-chunk-9-1.png differ