DensityGenes: Density Plots for a Set of Genes

View source: R/plots_functions.R

DensityGenesR Documentation

Density Plots for a Set of Genes

Description

Create highly customizable density plots for a given set of genes. Includes options to color for and group by various annotations.

Usage

DensityGenes(data, list, color.by = "blue", exact = TRUE, facet.annotation = FALSE,
  is.raw.Ct = FALSE, na.fix = 2, transparency = 0.5, ncols = 2, scales = "free",
  legend.position = "default", return.ggplot.input = FALSE)

Arguments

data

numeric data matrix with samples/observations in the columns and genes/variables in the rows

list

character vector of genes/variables to be pulled out of the data matrix for viewing

color.by

How the plots are colored and grouped. There are several different options that this argument can take. If set to a single color (the default, blue), one density plot will be shown in the indicated color. The name of an annotation can be provided that must match the colnames of the annotations dataframe stored in the params list object. If the colors of this annotation are also specified in annot_cols, also stored in the params list object, those colors will be used for the indicated levels of the annotation. If the colors are not provided, default colors will be used. In this case, multiple overlapping density plots will be shown separating the annotations. Useful for seeing if the range of data differs between different groups of samples.

exact

whether or not to search for exact or inexact matches of 'list' in 'data'. If exact = T (default) heatmap will plot genes/variables that exactly match the list supplied. If set to FALSE, will search for inexact matches.

facet.annotation

By default, when multiple genes are plotted the function will facet to separate the genes. If facet.annotation is set to "wrap" or "grid", will also separate by the annotation supplied for coloring. See facet_wrap and facet_grid for more information on faceting.

is.raw.Ct

logical. If set to TRUE, will reverse the scale of the data to indicate low values as high expression as in the case of raw Ct values from qPCR, in this case, missing values will also be set to a high value to reflect low expression level

na.fix

option to treat missing/NA values as an offset from the minimum value. Ex a value of 2 will set missing values to min(data) - 2. If coloring by a specific gene, will still be colored black. In na.fix=F missing values will be removed

transparency

transparency or alpha value of the fill for the density plots

ncols

how many columns in the facet. See facet_wrap

scales

freedom of scales in facets. See facet_wrap

legend.position

should the legend be shown and if so where should it be placed. If left as default, legend will be drawn at the right if colored by an annotation, otherwise will not be drawn, can be overwritten by setting the legend position to one of "top", "right","left","bottom","none".

return.ggplot.input

logical. If true, will return the input dataframe to the ggplot object. Useful if more customization is required.

Details

A density plot will be generated from the input data for each gene provided. Options to group and color the plots according to sample groups or annotations are acheived through use of the annotations dataframe stored in the params list object. See params, set_annotations, and set_annot_cols for more information on setting up annotations.

Value

A ggplot object. Additional layers can be added to the returned ggplot object to further customize theme and aesthetics.

If return.ggplot.input is set to TRUE, will return a list with the dataframe, coloring and call to ggplot for plotting.

'input_data'

the dataframe used for plotting which will contain the expression levels of the chosen genes (if values are squished to fit the plot the values will be similarly squished) as well as the annotations if available.

'coloring'

the coloring parameters used in the plot

plot_call

the call to ggplot that generated the plot. Note that simply accessing it by $plot_call will include escape characters. The full call can be accessed by cat(plot$plot_call). Please note that many of the parameters (those in lowercase) in the call are input parameters to the original function and must be input to properly recreate the plot.

Author(s)

~~Alison Moss~~

See Also

For more information on customizing the returned ggplot object, please see ggplot2 helpfiles, specifically those related to setting the theme.

See params, set_annotations, and set_annot_cols for more information on setting up annotations and associated colors.

Examples

##initiate_parameters
initiate_params()

##View density plots for selection of genes
DensityGenes(RAGP_norm, "Sst", exact = FALSE)  ##Sst and its receptors
DensityGenes(RAGP_rawCt, "Sst", exact = FALSE, is.raw.Ct = TRUE) #in raw Ct

##set up annotations and view distribution by annotation
set_annotations(RAGP_annots)
DensityGenes(RAGP_norm, "Sst", exact = FALSE, color.by = "State", ncols = 1)

axm323/dataVisEasy documentation built on Feb. 1, 2024, 11:53 p.m.