metsBoxplot: Creates layered boxplots of metabolite values across a class...

Description Usage Arguments Value Author(s) Examples

View source: R/metsBoxplot.R

Description

Boxplots are often useful for illustrating the distribution of metabolite values across a categorical outcome variable. metsBoxplot() will create these boxplots using ggplot2. The plots are somewhat customizable, and can be further customizable by including a custom theme object.

Usage

1
metsBoxplot(dat, classvar, metabolite, ylog = F, boxcolors = NULL, ref_line = NULL, title, subtitle = NULL, xlab = NULL, ylab = NULL, xaxis_size = 12, yaxis_size = 12, titlesize = 14, plot_theme = NULL)

Arguments

dat

Data frame used for the analysis

classvar

Factor variable used for the x-axis

metabolite

Character vector (length==1) of the COMP_ID used for the y-axis. May be raw or log transformed

ylog

Logical, Plot y-axis on a log10 scale.

boxcolors

Vector of colors equal to the length of levels(classvar). If you leave this NULL, a black and white image will be returned, but you can color each of the boxes if needed.

ref_line

Numeric vector indicating a horizontal reference line. You may want a line to indicate overall minimum or median, or any other reference you might like to plot.

title

Character vector of a plot title, optional.

subtitle

Character vector of a subtitle, optional

xlab

X-axis label. Defaults to the classvar.

ylab

Y-axis label. Defaults to metabolite COMP_ID

xaxis_size

Font size for x-axis

yaxis_size

Font size for y-axis

titlesize

Font size for title

plot_theme

You can create your own ggplot2 theme object and include it here. If you leave it as NULL, the plot will return with Brian's preferred aesthetic tastes, for better or worse.

Value

ggplot2 object.

Author(s)

Brian Carter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
breast <- getMetabolites("breast_metabolomics")

df <- left_join(survey,
                breast$metabolites,
                "ID")

df$BMICAT <- with(df,
                  ifelse(BMI < 18.5, 1, ifelse(
                       BMI < 25, 2, ifelse(
                            BMI < 30, 3, ifelse(
                                 BMI < 35, 4, 5)
                            )))) 
     factor(.,1:5, c("<18.5", "18.5-24.9",
                     "25-29.9", "30-34.9",
                     "35+"))

myplot <- metsBoxplot(dat=df,
            classvar="BMICAT",
            metabolite="X42459",
            ylog = T,
            boxcolors = c("royalblue","darkred","yellow",
                          "orange","forestgreen"),
            ref_line = min(df$X42459),
            title = "Title goes here",
            subtitle = "Subtitle goes here",
            xlab = "BMI Categories",
            ylab = "Sphingomyelin",
            xaxis_size = 12,
            yaxis_size = 12,
            titlesize = 14,
            plot_theme = NULL)


png("Boxplot.png", height=6, width=6, units="in", res=400)
myplot
dev.off()

buddha2490/BERGMets documentation built on Sept. 6, 2020, 5:11 p.m.