create.pgs.boxplot: Plot PGS Boxplots

View source: R/plot-pgs.R

create.pgs.boxplotR Documentation

Plot PGS Boxplots

Description

Plot boxplots of PGS data outputted by apply.polygenic.score. If phenotype columns are provided, multiple boxplots are plotted for automatically detected categories for each categorical variable.

Usage

create.pgs.boxplot(
  pgs.data,
  pgs.columns = NULL,
  phenotype.columns = NULL,
  add.stripplot = TRUE,
  jitter.factor = 1,
  output.dir = NULL,
  filename.prefix = NULL,
  file.extension = "png",
  tidy.titles = FALSE,
  alpha = 0.5,
  width = 10,
  height = 10,
  xaxes.cex = 1.5,
  yaxes.cex = 1.5,
  titles.cex = 1.5,
  border.padding = 1
)

Arguments

pgs.data

data.frame PGS data as formatted by apply.polygenic.score(). Required columns are at least one of PGS, PGS.with.replaced.missing, or PGS.with.normalized.missing. This function is designed to work with the output of apply.polygenic.score().

pgs.columns

character vector of column names indicating which columns in pgs.data to plot as PGSs. If NULL, defaults to recognized PGS columns: PGS, PGS.with.replaced.missing, and PGS.with.normalized.missing.

phenotype.columns

character vector of phenotype columns in pgs.data to plot (optional)

add.stripplot

logical whether to add a stripplot to the boxplot, defaults to TRUE

jitter.factor

numeric factor by which to scale the jitter (noise) applied to stripplot points, defaults to 1

output.dir

character directory to save output plots

filename.prefix

character prefix for output filenames

file.extension

character file extension for output plots

tidy.titles

logical whether to reformat PGS plot titles to remove periods

alpha

numeric alpha value for stripplot points, defaults to 0.5

width

numeric width of output plot in inches

height

numeric height of output plot in inches

xaxes.cex

numeric size for all x-axis labels

yaxes.cex

numeric size for all y-axis labels

titles.cex

numeric size for all plot titles

border.padding

numeric padding for plot borders

Value

If no output directory is provided, a multipanel lattice plot object is returned, otherwise a plot is written to the indicated path and NULL is returned.

Examples

set.seed(100);
pgs.data <- data.frame(
    PGS = rnorm(100, 0, 1)
    );
temp.dir <- tempdir();

# Basic Plot
create.pgs.boxplot(
   pgs.data,
   output.dir = temp.dir,
   filename.prefix = 'basic-plot',
   width = 6,
   height = 6
   );

# Plot multiple PGS outputs
pgs.data$PGS.with.normalized.missing <- rnorm(100, 1, 1);
create.pgs.boxplot(pgs.data, output.dir = temp.dir);

# Plot non-default PGS columns
pgs.data$PGS.custom <- rnorm(100, 2, 1);
create.pgs.boxplot(pgs.data, pgs.columns = 'PGS.custom', output.dir = temp.dir);
# Plot phenotype categories
pgs.data$sex <- sample(c('male', 'female'), 100, replace = TRUE);

create.pgs.boxplot(
    pgs.data,
    output.dir = temp.dir,
    filename.prefix = 'multiple-pgs',
    phenotype.columns = 'sex'
    );

# Plot multiple phenotypes
pgs.data$letters <- sample(letters[1:5], 100, replace = TRUE);

create.pgs.boxplot(
   pgs.data,
   output.dir = temp.dir,
   filename.prefix = 'multiple-phenotypes',
   phenotype.columns = c('sex', 'letters')
   );


ApplyPolygenicScore documentation built on Aug. 21, 2025, 5:43 p.m.