Merge branch 'master' of https://github.com/haozhu233/kableExtra
diff --git a/R/spec_tools.R b/R/spec_tools.R
index f62f9e3..47e51d1 100644
--- a/R/spec_tools.R
+++ b/R/spec_tools.R
@@ -3,11 +3,19 @@
#' @inheritParams viridisLite::viridis
#' @param x continuous vectors of values
#' @param na_color color code for NA values
+#' @param scale_from input range (vector of length two). If not given,
+#' is calculated from the range of x
#' @export
spec_color <- function(x, alpha = 1, begin = 0, end = 1,
direction = 1, option = "D",
- na_color = "#BBBBBB") {
- x <- round(rescale(x, c(1, 256)))
+ na_color = "#BBBBBB", scale_from = NA) {
+ if (is.na(scale_from)) {
+ x <- round(rescale(x, c(1, 256)))
+ } else {
+ x <- round(rescale(x, to = c(1, 256),
+ from = scale_from))
+ }
+
color_code <- viridisLite::viridis(256, alpha, begin, end, direction, option)[x]
color_code[is.na(color_code)] <- na_color
return(color_code)
@@ -45,9 +53,17 @@
#' @param begin Smalles font size to be used. Default is 10.
#' @param end Largest font size. Default is 20.
#' @param na_font_size font size for NA values
+#' @param scale_from input range (vector of length two). If not given,
+#' is calculated from the range of x
#' @export
-spec_font_size <- function(x, begin = 8, end = 16, na_font_size = 12) {
- x <- round(rescale(x, c(begin, end)))
+spec_font_size <- function(x, begin = 8, end = 16, na_font_size = 12,
+ scale_from = NA) {
+ if (is.na(scale_from)) {
+ x <- round(rescale(x, c(begin, end)))
+ } else {
+ x <- round(rescale(x, to = c(begin, end),
+ from = scale_from))
+ }
x[is.na(x)] <- na_font_size
return(x)
}
@@ -57,9 +73,16 @@
#' @param x continuous vectors of values
#' @param begin Smallest degree to rotate. Default is 0
#' @param end Largest degree to rotate. Default is 359.
+#' @param scale_from input range (vector of length two). If not given,
+#' is calculated from the range of x
#' @export
-spec_angle <- function(x, begin, end) {
- x <- round(rescale(x, c(begin, end)))
+spec_angle <- function(x, begin, end, scale_from = NA) {
+ if (is.na(scale_from)) {
+ x <- round(rescale(x, c(begin, end)))
+ } else {
+ x <- round(rescale(x, to = c(begin, end),
+ from = scale_from))
+ }
x[is.na(x)] <- 0
return(x)
}
diff --git a/man/spec_angle.Rd b/man/spec_angle.Rd
index 5df2b13..a68d6d6 100644
--- a/man/spec_angle.Rd
+++ b/man/spec_angle.Rd
@@ -4,7 +4,7 @@
\alias{spec_angle}
\title{Generate rotation angle for continuous values}
\usage{
-spec_angle(x, begin, end)
+spec_angle(x, begin, end, scale_from = NA)
}
\arguments{
\item{x}{continuous vectors of values}
@@ -12,6 +12,9 @@
\item{begin}{Smallest degree to rotate. Default is 0}
\item{end}{Largest degree to rotate. Default is 359.}
+
+\item{scale_from}{input range (vector of length two). If not given,
+is calculated from the range of x}
}
\description{
Generate rotation angle for continuous values
diff --git a/man/spec_color.Rd b/man/spec_color.Rd
index ab25980..131bcde 100644
--- a/man/spec_color.Rd
+++ b/man/spec_color.Rd
@@ -5,7 +5,7 @@
\title{Generate viridis Color code for continuous values}
\usage{
spec_color(x, alpha = 1, begin = 0, end = 1, direction = 1,
- option = "D", na_color = "#BBBBBB")
+ option = "D", na_color = "#BBBBBB", scale_from = NA)
}
\arguments{
\item{x}{continuous vectors of values}
@@ -25,6 +25,9 @@
and "viridis" (or "D", the default option).}
\item{na_color}{color code for NA values}
+
+\item{scale_from}{input range (vector of length two). If not given,
+is calculated from the range of x}
}
\description{
Generate viridis Color code for continuous values
diff --git a/man/spec_font_size.Rd b/man/spec_font_size.Rd
index aeacd93..9688dec 100644
--- a/man/spec_font_size.Rd
+++ b/man/spec_font_size.Rd
@@ -4,7 +4,8 @@
\alias{spec_font_size}
\title{Generate common font size for continuous values}
\usage{
-spec_font_size(x, begin = 8, end = 16, na_font_size = 12)
+spec_font_size(x, begin = 8, end = 16, na_font_size = 12,
+ scale_from = NA)
}
\arguments{
\item{x}{continuous vectors of values}
@@ -14,6 +15,9 @@
\item{end}{Largest font size. Default is 20.}
\item{na_font_size}{font size for NA values}
+
+\item{scale_from}{input range (vector of length two). If not given,
+is calculated from the range of x}
}
\description{
Generate common font size for continuous values