create.pgs.with.continuous.phenotype.plot: Plot PGS Scatterplots

View source: R/plot-pgs.R

create.pgs.with.continuous.phenotype.plotR Documentation

Plot PGS Scatterplots

Description

Create scatterplots for PGS data outputed by apply.polygenic.score() with continuous phenotype variables

Usage

create.pgs.with.continuous.phenotype.plot(
  pgs.data,
  phenotype.columns,
  hexbin.threshold = 1000,
  hexbin.colour.scheme = NULL,
  hexbin.colourkey = TRUE,
  hexbin.colourcut = seq(0, 1, length = 11),
  hexbin.mincnt = 1,
  hexbin.maxcnt = NULL,
  hexbin.xbins = 30,
  hexbin.aspect = 1,
  output.dir = NULL,
  filename.prefix = NULL,
  file.extension = "png",
  tidy.titles = FALSE,
  compute.correlation = TRUE,
  corr.legend.corner = c(0, 1),
  corr.legend.cex = 1.5,
  include.origin = FALSE,
  width = 10,
  height = 10,
  xaxes.cex = 1.5,
  yaxes.cex = 1.5,
  titles.cex = 1.5,
  point.cex = 0.75,
  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, and at least one continuous phenotype column. This function is designed to work with the output of apply.polygenic.score().

phenotype.columns

character vector of continuous phenotype column names in pgs.data to plot

hexbin.threshold

numeric threshold (exclusive) for cohort size at which to switch from scatterplot to hexbin plot.

hexbin.colour.scheme

character vector of colors for hexbin plot bins. Default is NULL which uses gray/black.

hexbin.colourkey

logical whether a legend should be drawn for a hexbinplot, defaults to TRUE.

hexbin.colourcut

numeric vector of values covering [0, 1] that determine hexagon colour class boundaries and hexagon legend size boundaries. Alternatively, an integer (<= hexbin.maxcnt) specifying the number of equispaced colourcut values in [0,1].

hexbin.mincnt

integer, minimum count for a hexagon to be plotted. Default is 1.

hexbin.maxcnt

integer, maximum count for a hexagon to be plotted. Cells with more counts are not plotted. Default is NULL.

hexbin.xbins

integer, number of bins in the x direction for hexbin plot. Default is 30.

hexbin.aspect

numeric, aspect ratio of hexbin plot to control plot dimensions. Default is 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

compute.correlation

logical whether to compute correlation between PGS and phenotype and display in plot

corr.legend.corner

numeric vector indicating the corner of the correlation legend e.g. c(0,1) for top left

corr.legend.cex

numeric cex for correlation legend

include.origin

logical whether to include the origin (zero) in plot axes

width

numeric width of output plot in inches

height

numeric height of output plot in inches

xaxes.cex

numeric size for x-axis labels

yaxes.cex

numeric size for y-axis labels

titles.cex

numeric size for plot titles

point.cex

numeric size for plot points

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. If no continuous phenotype variables are detected, a warning is issued and NULL is returned.

Examples

set.seed(100);

pgs.data <- data.frame(
    PGS = rnorm(100, 0, 1),
    continuous.phenotype = rnorm(100, 2, 1)
    );
 temp.dir <- tempdir();

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

# Plot multiple PGS outputs

pgs.data$PGS.with.normalized.missing <- rnorm(100, 1, 1);
create.pgs.with.continuous.phenotype.plot(
    pgs.data,
    output.dir = temp.dir,
    filename.prefix = 'multiple-pgs',
    phenotype.columns = 'continuous.phenotype'
    );


# Plot multiple phenotypes

pgs.data$continuous.phenotype2 <- rnorm(100, 10, 1);
create.pgs.with.continuous.phenotype.plot(
    pgs.data,
    output.dir = temp.dir,
    filename.prefix = 'multiple-phenotypes',
    phenotype.columns = c('continuous.phenotype', 'continuous.phenotype2')
    );


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