Skip to contents

Designed for use with layer_group_data. group_data_pal generates palettes that are passed to ggplot2::scale_fill_manual and ggplot2::scale_color_manual.

Usage

scale_group_data(
  ...,
  data,
  col = NULL,
  palette = NULL,
  n = NULL,
  direction = 1,
  na.value = "grey50",
  drop = FALSE,
  limits = NULL,
  aesthetics = "fill"
)

group_data_pal(data, palette = NULL, col = NULL, n = NULL, direction = 1)

get_group_data_pal_scale(data, col = NULL, palette = NULL, ...)

Arguments

...

Arguments passed on to discrete_scale

palette

A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that they should take (e.g., scales::hue_pal()).

limits

One of:

  • NULL to use the default scale values

  • A character vector that defines possible values of the scale and their order

  • A function that accepts the existing (automatic) values and returns new ones. Also accepts rlang lambda function notation.

drop

Should unused factor levels be omitted from the scale? The default, TRUE, uses the levels that appear in the data; FALSE uses all the levels in the factor.

na.translate

Unlike continuous scales, discrete scales can easily show missing values, and do so by default. If you want to remove missing values from a discrete scale, specify na.translate = FALSE.

scale_name

The name of the scale that should be used for error messages associated with this scale.

name

The name of the scale. Used as the axis or legend title. If waiver(), the default, the name of the scale is taken from the first mapping used for that aesthetic. If NULL, the legend title will be omitted.

labels

One of:

  • NULL for no labels

  • waiver() for the default labels computed by the transformation object

  • A character vector giving labels (must be same length as breaks)

  • A function that takes the breaks as input and returns labels as output. Also accepts rlang lambda function notation.

guide

A function used to create a guide or its name. See guides() for more information.

super

The super class to use for the constructed scale

data

Data to use when generating scale or palette.

col

Grouping column found in data to use in generating scale or palette; defaults to NULL.

palette

Name of palette as a string. Must be on the form packagename::palettename.

n

Number of colors desired. If omitted, returns complete palette.

direction

Either 1 or -1. If -1 the palette will be reversed.

na.value

The aesthetic value to use for missing (NA) values

drop

Should unused factor levels be omitted from the scale? The default, TRUE, uses the levels that appear in the data; FALSE uses all the levels in the factor.

limits

One of:

  • NULL to use the default scale values

  • A character vector that defines possible values of the scale and their order

  • A function that accepts the existing (automatic) values and returns new ones. Also accepts rlang lambda function notation.

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").