R/label-scales.R

Defines functions scale_label_size_continuous scale_label_alpha_continuous scale_label_colour_continuous

Documented in scale_label_alpha_continuous scale_label_colour_continuous scale_label_size_continuous

#' Scales for contour label aesthetics
#'
#' @param aesthetics Character string or vector of character strings listing the
#' name(s) of the aesthetic(s) that this scale works with. This can be useful,
#' for example, to apply colour settings to the colour and fill aesthetics at
#' the same time, via aesthetics = c("colour", "fill").
#' @param guide Type of legend. Use "colourbar" for continuous colour bar,
#'  or "legend" for discrete colour legend.
#'
#' @export
#' @rdname label_scales
scale_label_colour_continuous <- function(
  ...,
  aesthetics = c("label_colour"),
  guide = ggplot2::guide_colorbar(available_aes = "label_colour")
) {
  ggplot2::scale_color_continuous(..., aesthetics = aesthetics, guide = guide)
}

#' @param range Output range of alpha values. Must lie between 0 and 1.
#' @export
#' @rdname label_scales
scale_label_alpha_continuous <- function(
  ...,
  range = c(0.1, 1),
  aesthetics = c("label_alpha")
) {
  ggplot2::continuous_scale(
    aesthetics = "label_alpha",
    palette = scales::rescale_pal(range),
    ...
  )
}

#' @inheritParams ggplot2::scale_size
#' @export
#' @rdname label_scales
scale_label_size_continuous <- function(
  breaks = waiver(),
  labels = waiver(),
  limits = NULL,
  range = c(1, 6),
  transform = "identity",
  guide = "legend"
) {
  ggplot2::continuous_scale(
    aesthetics = "label_size",
    palette = scales::area_pal(range),
    breaks = breaks,
    labels = labels,
    limits = limits,
    transform = transform
  )
}

Try the metR package in your browser

Any scripts or data that you put into this service are public.

metR documentation built on Oct. 8, 2026, 9:17 a.m.