Parcourir la source

Fixup scale_xaringan...()

tags/v0.3.0
Garrick Aden-Buie il y a 7 ans
Parent
révision
7202d2ab5a
2 fichiers modifiés avec 30 ajouts et 27 suppressions
  1. +20
    -20
      R/ggplot2.R
  2. +10
    -7
      man/scale_xaringan.Rd

+ 20
- 20
R/ggplot2.R Voir le fichier

axis.title = ggplot2::element_text(size = title_font_size * 0.8), axis.title = ggplot2::element_text(size = title_font_size * 0.8),
axis.ticks = ggplot2::element_line(color = blend(0.8)), axis.ticks = ggplot2::element_line(color = blend(0.8)),
axis.text = ggplot2::element_text(color = blend(0.4)), axis.text = ggplot2::element_text(color = blend(0.4)),
legend.key = element_rect(fill="transparent", colour=NA),
plot.caption = ggplot2::element_text( plot.caption = ggplot2::element_text(
size = text_font_size * 0.8, size = text_font_size * 0.8,
color = blend(0.3)) color = blend(0.3))
#' @param direction Direction of the discrete scale. Use values less than 0 to #' @param direction Direction of the discrete scale. Use values less than 0 to
#' reverse the direction, e.g. `direction = -1`. #' reverse the direction, e.g. `direction = -1`.
#' @inheritParams colorspace::scale_color_continuous_sequential #' @inheritParams colorspace::scale_color_continuous_sequential
#' @param ... Additional arguments passed to [ggplot2::continuous_scale()] or
#' [ggplot2:discrete_scale()].
#' @param aes_type The type of aesthetic to which the scale is being applied. #' @param aes_type The type of aesthetic to which the scale is being applied.
#' One of "color", "colour", or "fill". #' One of "color", "colour", or "fill".
#' @name scale_xaringan #' @name scale_xaringan
color <- hex2HCL(get_theme_accent_color(color, inverse)) color <- hex2HCL(get_theme_accent_color(color, inverse))


pal <- function(n) { pal <- function(n) {
if (direction >= 0) {
colorspace::sequential_hcl(
n = n, c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"],
...
)
} else {
colorspace::sequential_hcl(
n = n, c2 = color[1, "C"], l2 = color[1, "L"], h2 = color[1, "H"],
...
)
}
colors <- colorspace::sequential_hcl(
n = n,
c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"],
rev = direction >= 1
)
} }


ggplot2::discrete_scale(aes_type, "manual", pal, ...) ggplot2::discrete_scale(aes_type, "manual", pal, ...)
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))


scale_fn <- switch(
aes_type,
colour = , color = colorspace::scale_color_continuous_sequential,
fill = colorspace::scale_fill_continuous_sequential
colors <- colorspace::sequential_hcl(
n = 12, c1 = color[1, "C"], l1 = color[1, "L"], h1 = color[1, "H"],
rev = TRUE
) )


scale_fn(
c1 = color[1, "C"],
l1 = color[1, "L"],
h1 = color[1, "H"],
begin = begin, end = end,
rescaler <- function(x, ...) {
scales::rescale(x, to = c(begin, end), from = range(x, na.rm = TRUE))
}

ggplot2::continuous_scale(
aes_type, "continuous_sequential",
palette = scales::gradient_n_pal(colors, values = NULL),
rescaler = rescaler,
oob = scales::censor,
... ...
) )
} }

+ 10
- 7
man/scale_xaringan.Rd Voir le fichier

scale_xaringan_continuous(aes_type = c("color", "colour", "fill"), ..., scale_xaringan_continuous(aes_type = c("color", "colour", "fill"), ...,
color = NULL, begin = 0, end = 1, inverse = FALSE) color = NULL, begin = 0, end = 1, inverse = FALSE)


scale_xaringan_fill_continuous(..., color = NULL, direction = 1,
scale_xaringan_fill_continuous(..., color = NULL, begin = 0, end = 1,
inverse = FALSE) inverse = FALSE)


scale_xaringan_color_continuous(..., color = NULL, direction = 1,
inverse = FALSE)
scale_xaringan_color_continuous(..., color = NULL, begin = 0,
end = 1, inverse = FALSE)


scale_xaringan_colour_continuous(..., color = NULL, direction = 1,
inverse = FALSE)
scale_xaringan_colour_continuous(..., color = NULL, begin = 0,
end = 1, inverse = FALSE)
} }
\arguments{ \arguments{
\item{aes_type}{The type of aesthetic to which the scale is being applied. \item{aes_type}{The type of aesthetic to which the scale is being applied.
\item{begin}{Number in the range of \code{[0, 1]} indicating to which point in the color scale the smallest data value should be mapped.} \item{begin}{Number in the range of \code{[0, 1]} indicating to which point in the color scale the smallest data value should be mapped.}


\item{end}{Number in the range of \code{[0, 1]} indicating to which point in the color scale the largest data value should be mapped.} \item{end}{Number in the range of \code{[0, 1]} indicating to which point in the color scale the largest data value should be mapped.}

\item{...}{Additional arguments passed to \code{\link[ggplot2:continuous_scale]{ggplot2::continuous_scale()}} or
\code{\link[=ggplot2:discrete_scale]{ggplot2:discrete_scale()}}.}
} }
\description{ \description{
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.
} }

Chargement…
Annuler
Enregistrer