plot_polymr: Plot results of PolyMR

View source: R/plot_polymr.R

plot_polymrR Documentation

Plot results of PolyMR

Description

This function provides an easy interface to quickly visualize the results from PolyMR using ggplot2.

Usage

plot_polymr(
  polymr_results,
  show_polymr = TRUE,
  show_observational = TRUE,
  show_binned_observations = TRUE,
  show_confidence_ribbons = TRUE,
  scale_values = TRUE,
  output_filename = NULL,
  main_title = "Effects of exposure on outcome",
  subtitle = NULL,
  auto_subtitle = TRUE,
  xlab = ifelse(scale_values, "Exposure (scaled)", "Exposure"),
  ylab = ifelse(scale_values, "Outcome (scaled)", "Outcome"),
  ylims = NULL,
  show_legend = TRUE,
  ggsave_options = list(width = 18, height = 18, units = "cm"),
  n_points = 1000
)

Arguments

polymr_results

A list containing the results from the polymr function.

show_polymr

Boolean indicating whether or not to plot the inferred causal function (default is TRUE).

show_observational

Boolean indicating whether or not to plot the observed association. Requires the observational association to have been estimated by the polymr function using return_observational_function = TRUE. Default is TRUE.

show_binned_observations

Boolean indicating whether or not to plot the binned observations, specifically the median exposure and outcome for each bin. Requires the binned values to have been returned by the polymr function using return_binned_observations = TRUE. Default is TRUE.

show_confidence_ribbons

Boolean indicating whether or not to display the 95% confidence hulls (default is TRUE).

scale_values

Boolean indicating whether or not to leave phenotypes (exposure and outcome) standardized with mean 0 and variance 1 or convert them back to their original range using the values in phenotypes_summary. Default is TRUE, indicating that the values will be plotted on a standard scale.

output_filename

The file name of the plot to be saved, if any. This will override any filename provided in ggsave_options. Default is NULL, in which case the plot will not be saved.

main_title

Main title of the plot (default is "Effect of exposure on outcome").

subtitle

Subtitle of the plot. If auto_subtitle is enabled, this will be prepended to the automatic subtitle. Default is NULL.

auto_subtitle

Whether to create and include a summary of results as subtitle. This summary includes the p-values and variance explained for the plotted functions (total variance for the observational association, causal variance for PolyMR). Default is TRUE.

xlab

Label for the X axis. Default is "Exposure (scaled)" if scale_values is TRUE and "Exposure" otherwise.

ylab

Label for the Y axis. Default is "Outcome (scaled)" if scale_values is TRUE and "Outcome" otherwise.

ylims

An optional vector of length 2 defining the boundaries of the plotted region on the Y axis. Default is NULL, relying on ggplot2 standard behavior.

show_legend

Whether or not to display the legend next to the plot (default is TRUE).

ggsave_options

A list of options to provide to ggplot2::ggsave. Ignored if no filename is specified here or using output_filename. Default is a list specifying a width and height both equal to 18 cm.

n_points

Number of points to plot in rendering the curve. Default is 1000, resulting in a smooth enough curve for most purposes.

Details

The plot is created using the gpplot2 library. The resulting plot can be customized using the standard ggplot2 functions.

Value

An object of the gg and ggplot classes.


JonSulc/PolyMR documentation built on April 26, 2023, 10:42 a.m.