A ggplot scale for pneumococcal serotypes that keeps PCV groups together
Source:R/utils-serotype-scales.R
scale_fill_serotype.Rd
The scale groups colours by PCV group, but it is important to have the source
data using the same levels as this scale otherwise the colour legend will be
ordered in a different sequence. This can be achieved using relevel_serotypes
,
Usage
scale_fill_serotype(
...,
palette_fn = scales::brewer_pal(palette = "Dark2"),
undefined = "#606060",
exprs = rlang::exprs()
)
Arguments
- ...
an unwrapped version of the
exprs
parameter Named arguments passed on toggplot2::scale_fill_manual
values
a set of aesthetic values to map data values to. The values will be matched in order (usually alphabetical) with the limits of the scale, or with
breaks
if provided. If this is a named vector, then the values will be matched based on the names instead. Data values that don't match will be givenna.value
.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
andfill
aesthetics at the same time, viaaesthetics = c("colour", "fill")
.breaks
One of:
NULL
for no breakswaiver()
for the default breaks (the scale limits)A character vector of breaks
A function that takes the limits as input and returns breaks as output
na.value
The aesthetic value to use for missing (
NA
) values
- palette_fn
a function that returns a set of colours for a number of levels. Such functions can be obtained from things like
scales::brewer_pal(...)
- undefined
the colour for the last group which is assumed to be the
Unknown
types- exprs
a list of formulae with a predicate on the LHS and a PCV group name on the RHS. which are interpreted as the parameters for a
dplyr::case_when
call. This must be protected against interpretation by wrapping it inrlang::exprs()
. The predicates are tested againstavoncap::serotype_data$map
and could use any of the following columns 'serotype', 'PCV7', 'PCV13', 'PCV15', 'PCV20', 'PPV23', 'PCV13on7', 'PCV15on13', 'PCV20on15', 'PPV23on20', 'PCV10SSI', 'PCV10GSK', 'PCV15Zhifei', 'PCV24Vaxcyte', 'PCV24Affinivax' a default option of the formTRUE ~ "Non PCV serotype"
must exist to capture unmatched items.