A ggplot scale for pneumococcal serotypes that keeps PCV groups together
Source:R/utils-serotype-scales.R
scale_fill_serotype.RdThe 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
exprsparameter Named arguments passed on toggplot2::scale_fill_manualvaluesa 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
breaksif 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.aestheticsCharacter 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
colourandfillaesthetics at the same time, viaaesthetics = c("colour", "fill").breaksOne of:
NULLfor 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.valueThe 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
Unknowntypes- 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_whencall. This must be protected against interpretation by wrapping it inrlang::exprs(). The predicates are tested againstavoncap::serotype_data$mapand 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.