create.pgs.density.plot: Plot PGS Density

View source: R/plot-pgs.R

create.pgs.density.plotR Documentation

Plot PGS Density

Description

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

Usage

create.pgs.density.plot(
  pgs.data,
  pgs.columns = NULL,
  phenotype.columns = NULL,
  output.dir = NULL,
  filename.prefix = NULL,
  file.extension = "png",
  tidy.titles = FALSE,
  width = 10,
  height = 10,
  xaxes.cex = 1.5,
  yaxes.cex = 1.5,
  titles.cex = 1.5,
  key.cex = 1,
  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)

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

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

key.cex

numeric size of color key legend

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.density.plot(
    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.density.plot(pgs.data, output.dir = temp.dir);

# Plot non-default PGS columns
pgs.data$PGS.custom <- rnorm(100, 2, 1);
create.pgs.density.plot(pgs.data, pgs.columns = 'PGS.custom', output.dir = temp.dir);

# Plot phenotype categories
pgs.data$sex <- sample(c('male', 'female'), size = 100, replace = TRUE);

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


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

create.pgs.density.plot(
    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.