Przeglądaj źródła

Fix scale_xaringan_discrete()

tags/v0.3.0
Garrick Aden-Buie 7 lat temu
rodzic
commit
f642e56e7a
1 zmienionych plików z 18 dodań i 20 usunięć
  1. +18
    -20
      R/ggplot2.R

+ 18
- 20
R/ggplot2.R Wyświetl plik



#' Xaringan Themer ggplot2 Scales #' Xaringan Themer ggplot2 Scales
#' #'
#' Color and fill scales for discrete and continuous values, created using the
#' primary accent color of the xaringanthemer styles.
#' Color and fill single-color scales for discrete and continuous values,
#' created using the primary accent color of the xaringanthemer styles.
#' #'
#' @param ... Arguments passed on to the appropriate scale function, one of #' @param ... Arguments passed on to the appropriate scale function, one of
#' [colorspace::scale_color_discrete_sequential], #' [colorspace::scale_color_discrete_sequential],
aes_type <- match.arg(aes_type) aes_type <- match.arg(aes_type)
color <- hex2HCL(get_theme_accent_color(color, inverse)) color <- hex2HCL(get_theme_accent_color(color, inverse))


if (direction >= 0) {
if (aes_type %in% c("color", "colour")) {
colorspace::scale_color_discrete_sequential(
c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"], ...)
} else {
colorspace::scale_fill_discrete_sequential(
c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"], ...)
}
} else {
if (aes_type %in% c("color", "colour")) {
colorspace::scale_color_discrete_sequential(
c2 = color[1, "C"], l2 = color[1, "L"], h2 = color[1, "H"], ...)
pal <- function(n) {
if (direction >= 0) {
colorspace::sequential_hcl(
n = n, c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"],
...
)
} else { } else {
colorspace::scale_fill_discrete_sequential(
c2 = color[1, "C"], l2 = color[1, "L"], h2 = color[1, "H"], ...)
colorspace::sequential_hcl(
n = n, c2 = color[1, "C"], l2 = color[1, "L"], h2 = color[1, "H"],
...
)
} }
} }

ggplot2::discrete_scale(aes_type, "manual", pal, ...)
} }


#' @rdname scale_xaringan #' @rdname scale_xaringan
#' @rdname scale_xaringan #' @rdname scale_xaringan
#' @export #' @export
scale_xaringan_fill_continuous <- function( scale_xaringan_fill_continuous <- function(
..., color = NULL, direction = 1, inverse = FALSE
..., color = NULL, begin = 0, end = 1, inverse = FALSE
) { ) {
scale_xaringan_continuous( scale_xaringan_continuous(
"fill", ..., color = color, direction = direction, inverse = inverse
"fill", ..., color = color, begin = begin, end = end, inverse = inverse
) )
} }


#' @rdname scale_xaringan #' @rdname scale_xaringan
#' @export #' @export
scale_xaringan_color_continuous <- function( scale_xaringan_color_continuous <- function(
..., color = NULL, direction = 1, inverse = FALSE
..., color = NULL, begin = 0, end = 1, inverse = FALSE
) { ) {
scale_xaringan_continuous( scale_xaringan_continuous(
"color", ..., color = color, direction = direction, inverse = inverse
"color", ..., color = color, begin = begin, end = end, inverse = inverse
) )
} }



Ładowanie…
Anuluj
Zapisz