Generate a Stacked Bar Plot of MIC Values Colored by Gene Symbol for Each Antibiotic
Source:R/AMRgen_barplot_mic_gen_v1.0.R
AMRgen_barplot_mic_gen.Rd
This function creates a stacked bar plot using ggplot2
, where the x-axis represents MIC (Minimum Inhibitory Concentration) values,
the y-axis represents their frequency, and the bars are colored by the gene symbols. The plot is faceted by antibiotic.
Usage
AMRgen_barplot_mic_gen(
pheno_data,
geno_data,
pathogen_mo,
abs_to_plot,
pheno_sample_col = NULL,
geno_sample_col = NULL,
measure_method = "mic",
breakpoint_source = paste("EUCAST", as.numeric(format(Sys.Date(), "%Y")) - 2),
breakpoint_type = "ECOFF",
color_by = "gene",
plot_title = "Frequency distribution of values for different genotypes",
leg_pos = "bottom",
ncol_leg = min(2, round(length(unique(geno_data$marker))/10))
)
Arguments
- pheno_data
A data.frame read in by the phenotypic parser, containing a column listing the sample ID, "spp_pheno" (class mo), "drug_agent" (class ab), "mic" (class mic), "disk" (class disk). The sample ID column is used to match to geno_data.
- geno_data
A data.frame generated by the genotypic parser, containing a sample ID column, "marker" (class gene), "drug_agent" (class ab, note this value can be NA if there is no specific agent), and "drug_class" (controlled vocab of drug classes for the AMR package)
- pathogen_mo
A string in mo format specifying what pathogen is used to select breakpoints, e.g. 'B_STPHY_AURS'
- abs_to_plot
A vector of strings listing the antibiotic drugs you wish to plot. Need to be in three letter code format as per the AMR package
- pheno_sample_col
The name of the sample column in pheno_data, defaults to first column
- geno_sample_col
The name of the sample column in geno_data, defaults to first column
- measure_method
A string specifying the method used to measure antimicrobial resistance. The default is 'mic' for Minimum Inhibitory Concentration, the other option is 'disk' for Disk Diffusion.
- breakpoint_source
A string representing the source for breakpoint data. By default, it is set to EUCAST 2023.
- breakpoint_type
A string specifying the type of breakpoint to use, default is 'ECOFF'.
- color_by
A string specifying the variable used to color the plot elements. Options include 'gene' (default) to color by gene, or 'class' to color by drug class. Any other strings also default to gene.
- plot_title
A string specifying the title of the plot. The default title is "Frequency distribution of values for different genotypes".
- leg_pos
A string specifying the position of the plot's legend. The default is 'bottom', but other options include 'top', 'left', or 'right'.
- ncol_leg
An integer specifying the number of columns for the legend. By default, it is calculated based on the number of unique gene symbols in
geno_data
, rounded to 10 items per column, but minimally 2. This ensures the legend is well-organized when there are many gene symbols.
Details
The function automatically groups the data by
Antibiotic
,MIC (mg/L)
, andGene symbol
and calculates the frequency of occurrences.The plot uses the
viridis
color scale with the "turbo" palette by default. You can replace it with your custom palette if desired.
Examples
if (FALSE) { # \dontrun{
AMRgen_barplot_mic_gen(pheno_data,
geno_data,
abs_to_plot = c("CIP", "IPM", "MEM"),
measure_method = "mic",
pathogen_mo = "B_ESCHR_COLI"
)
} # }