graph_species_names: Italicise species names for graphing Producing mixed italics...

View source: R/graph_species_names.R

graph_species_namesR Documentation

Italicise species names for graphing Producing mixed italics for species names in plots is tricky. This function will do it for the species in the mandatory surveillance collections

Description

Italicise species names for graphing Producing mixed italics for species names in plots is tricky. This function will do it for the species in the mandatory surveillance collections

Usage

graph_species_names(x)

Arguments

x

a character vector giving the data collection

Value

A factor variable with labels that will control italicisation

Examples

graph_species_names("Klebsiella spp")
graph_species_names("MRSA")
graph_species_names(x = c("Klebsiella spp", "MRSA"))
graph_species_names <- function(x){
  assertthat::assert_that(is.character(x), msg = "x must be a character")
  x <- trimws(x)
  assertthat::assert_that(
    all(x %in% c("C. difficile", "E. coli","Klebsiella spp", "MRSA", "MSSA",
                  "P. aeruginosa", "Pseudomonas aeruginosa")),
                  msg = "Please make sure that x is one of C. difficile, E. coli,
                  Klebsiella spp, MRSA, MSSA, P. aeruginosa or Pseudomonas aeruginosa,
    S. aureus or Staphylococcus aureus"
    )
  x <- ifelse(x == "Pseudomonas aeruginosa", "P. aeruginosa", x)
  x <- factor(x)
  levels(x) = c("C. difficile" = expression(italic("C. difficile")),
                "E. coli" = expression(italic("E. coli")),
                "Klebsiella spp" = expression(paste(italic("Klebsiella "), " spp.")),
                "MRSA" = "MRSA",
                "MSSA" = "MSSA",
                "P. aeruginosa" = expression(italic("P. aeruginosa")),
                "S. aureus" = expression(italic("S. aureus"))
  )
  x <- droplevels(x)
  return(x)
}

PublicHealthEngland/hcaidcs documentation built on Jan. 19, 2024, 8:38 a.m.