create.pgs.rank.plot: Plot PGS Rank

View source: R/plot-pgs-rank.R

create.pgs.rank.plotR Documentation

Plot PGS Rank

Description

Plot PGS percentile rank of each sample outputted by apply.polygenic.score() as a barplot, plot missing genotypes if any are present, plot corresponding decile and quartile markers as a heatmap, optionally plot phenotype covariates as color bars.

Usage

create.pgs.rank.plot(
  pgs.data,
  phenotype.columns = NULL,
  missing.genotype.style = "count",
  categorical.palette = NULL,
  binary.palette = NULL,
  output.dir = NULL,
  filename.prefix = NULL,
  file.extension = "png",
  width = 8,
  height = 8,
  xaxis.cex = 1.2,
  yaxis.cex = 1,
  titles.cex = 1.2,
  border.padding = 1
)

Arguments

pgs.data

data.frame PGS data as formatted by apply.polygenic.score() Required columns: Indiv, percentile, decile, quartile, n.missing.genotypes, percent.missing.genotypes, and optionally user-defined percentiles and phenotype covariates. This function is designed to work with the output of the function apply.polygenic.score().

phenotype.columns

character vector of column names in pgs.data containing phenotype covariates to plot as color bars. Default is NULL.

missing.genotype.style

character style of missing genotype barplot. Default is "count". Options are "count" or "percent".

categorical.palette

character vector of colors to use for categorical phenotype covariates. Default is NULL in which case the default palette is used, which contains 12 unique colors. If the number of unique categories exceeds the number of colors in the color palette, an error will be thrown.

binary.palette

character vector of colors to use for binary and continuous phenotype covariates. Each color is contrasted with white to create a color ramp or binary categories. Default is NULL in which case the default palette is used, which contains 9 unique colors paired with white. If the number of binary and continuous phenotype covariates exceeds the number of colors in the color palette, an error will be thrown.

output.dir

character directory path to write plot to file. Default is NULL in which case the plot is returned as lattice multipanel object.

filename.prefix

character prefix for plot filename.

file.extension

character file extension for plot file. Default is "png".

width

numeric width of plot in inches.

height

numeric height of plot in inches.

xaxis.cex

numeric size of x-axis labels.

yaxis.cex

numeric size of y-axis labels.

titles.cex

numeric size of plot titles.

border.padding

numeric padding around plot border.

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.

For clarity, certain plot aspects change when sample size exceeds 50:

  • x-axis labels are no longer displayed

  • missing (NA) values are not labeled with text in heatmaps but are color-coded with a legend

Colors for continuous and binary phenotypes are chosen from the binary color palettes in BoutrosLab.plotting.general::default.colours(). Colors for categorical phenotypes are chosen by default from the qualitative color palette in BoutrosLab.plotting.general::default.colours().

Examples

set.seed(200);
percentiles <- get.pgs.percentiles(rnorm(200, 0, 1));
pgs.data <- data.frame(
    Indiv = paste0('sample', 1:200),
    percentile = percentiles$percentile,
    decile = percentiles$decile,
    quartile = percentiles$quartile,
    n.missing.genotypes = sample(1:10, 200, replace = TRUE),
    percent.missing.genotypes = sample(1:10, 200, replace = TRUE) / 100,
    continuous.pheno = rnorm(200, 1, 1),
    categorical.pheno = sample(letters[1:5], 200, replace = TRUE),
    binary.pheno = sample(c(0,1), 200, replace = TRUE)
    );

temp.dir <- tempdir();

create.pgs.rank.plot(
    pgs.data,
    phenotype.columns = c('continuous.pheno', 'categorical.pheno', 'binary.pheno'),
    missing.genotype.style = 'percent',
    output.dir = temp.dir,
    filename.prefix = 'example-rank-plot'
    );

ApplyPolygenicScore documentation built on April 4, 2025, 12:18 a.m.