Просмотр исходного кода

Fixup scale_xaringan...()

tags/v0.3.0
Garrick Aden-Buie 7 лет назад
Родитель
Сommit
7202d2ab5a
2 измененных файлов: 30 добавлений и 27 удалений
  1. +20
    -20
      R/ggplot2.R
  2. +10
    -7
      man/scale_xaringan.Rd

+ 20
- 20
R/ggplot2.R Просмотреть файл

@@ -230,6 +230,7 @@ theme_xaringan_base <- function(
axis.title = ggplot2::element_text(size = title_font_size * 0.8),
axis.ticks = ggplot2::element_line(color = blend(0.8)),
axis.text = ggplot2::element_text(color = blend(0.4)),
legend.key = element_rect(fill="transparent", colour=NA),
plot.caption = ggplot2::element_text(
size = text_font_size * 0.8,
color = blend(0.3))
@@ -371,6 +372,8 @@ safely_set_geom <- function(geom, new) {
#' @param direction Direction of the discrete scale. Use values less than 0 to
#' reverse the direction, e.g. `direction = -1`.
#' @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.
#' One of "color", "colour", or "fill".
#' @name scale_xaringan
@@ -389,17 +392,11 @@ scale_xaringan_discrete <- function(
color <- hex2HCL(get_theme_accent_color(color, inverse))

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, ...)
@@ -438,17 +435,20 @@ scale_xaringan_continuous <- function(
aes_type <- match.arg(aes_type)
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 Просмотреть файл

@@ -27,14 +27,14 @@ scale_xaringan_colour_discrete(..., color = NULL, direction = 1,
scale_xaringan_continuous(aes_type = c("color", "colour", "fill"), ...,
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)

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{
\item{aes_type}{The type of aesthetic to which the scale is being applied.
@@ -60,8 +60,11 @@ value of \code{inverse_header_color}}
\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{...}{Additional arguments passed to \code{\link[ggplot2:continuous_scale]{ggplot2::continuous_scale()}} or
\code{\link[=ggplot2:discrete_scale]{ggplot2:discrete_scale()}}.}
}
\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.
}

Загрузка…
Отмена
Сохранить