Hao Zhu | 9ce317e | 2017-10-12 18:19:55 -0400 | [diff] [blame] | 1 | #' Generate viridis Color code for continuous values |
| 2 | #' |
| 3 | #' @inheritParams viridisLite::viridis |
| 4 | #' @param x continuous vectors of values |
| 5 | #' @param na_color color code for NA values |
| 6 | #' @export |
| 7 | spec_color <- function(x, alpha = 1, begin = 0, end = 1, |
| 8 | direction = 1, option = "D", |
| 9 | na_color = "#BBBBBBFF") { |
| 10 | x <- round(rescale(x, c(1, 256))) |
| 11 | color_code <- viridisLite::viridis(256, alpha, begin, end, direction, option)[x] |
| 12 | color_code[is.na(color_code)] <- na_color |
| 13 | return(color_code) |
| 14 | } |
| 15 | |
| 16 | #' Generate common font size for continuous values |
| 17 | #' |
| 18 | #' @param x continuous vectors of values |
| 19 | #' @param begin Smalles font size to be used. Default is 10. |
| 20 | #' @param end Largest font size. Default is 20. |
| 21 | #' @param na_font_size font size for NA values |
| 22 | #' @export |
| 23 | spec_font_size <- function(x, begin = 10, end = 20, na_font_size = "inherit") { |
| 24 | x <- round(rescale(x, c(begin, end))) |
| 25 | x[is.na(x)] <- na_font_size |
| 26 | return(x) |
| 27 | } |
| 28 | |
| 29 | #' Generate rotation angle for continuous values |
| 30 | #' |
| 31 | #' @param x continuous vectors of values |
| 32 | #' @param begin Smallest degree to rotate. Default is 0 |
| 33 | #' @param end Largest degree to rotate. Default is 359. |
| 34 | #' @export |
| 35 | spec_angle <- function(x) { |
| 36 | x <- round(rescale(x, c(0, 359))) |
| 37 | x[is.na(x)] <- 0 |
| 38 | return(x) |
| 39 | } |