horizonaes: Add Custom Aesthetics to the Horizon Plot

View source: R/BiomeHorizon.R

horizonaesR Documentation

Add Custom Aesthetics to the Horizon Plot

Description

Add additional aesthetics to the horizon plot object, returning them in the form of a list of ggplot aesthetics to supply to horizonplot().

Usage

horizonaes(
  title = NA,
  subtitle = NA,
  xlabel = NA,
  ylabel = NA,
  showColorLegend = TRUE,
  showLegendLabels = TRUE,
  legendPosition = "right",
  legendTitle = NA,
  showPlotLabels = TRUE,
  col.bands = NA,
  col.outline = "#CCCCCC",
  col.border = "#CCCCCC"
)

Arguments

title

character. The text for the title.

subtitle

character. The text for the subtitle, displayed below the title.

xlabel

character. The text for the x-axis label. If NA, uses a default label: "Sample" if data is not regularized, or "Day" if data is adjusted to regular time intervals.

ylabel

character. The text for the y-axis label.

showColorLegend

logical. If TRUE (the default) the color scale legend is drawn. Colors are displayed with the highest band on top and the lowest band on the bottom. For horizontal legends, higher bands will appear to the right and lower bands to the left.

showLegendLabels

logical. If TRUE (the default), labels indicating band number are shown on the color scale legend.

legendPosition

character. Where should the color scale legend be displayed? Possible values are "right" (the default), "left", "top", and "bottom". For the latter two options, the legend will appear horizontal.

legendTitle

character. The text for the title of the color scale legend.

showPlotLabels

logical. If TRUE (the default), labels for OTU subplots are shown.

col.bands

character vector of hexadecimal color codes giving the color scale for horizon bands. Colors should be specified from the most negative band to the most positive band. Must be the same length as 2*nbands. If NA, uses a default Red-Blue color gradient of a length determined by nbands in prepanel(). In this palette, darker shades of red indicate progressively more negative bands, while darker shades of blue indicate increasingly positive bands.

col.outline

character string specifying the hexadecimal color code for the outline on top of the graph of each band. If NULL, the outline will be removed. Defaults to light gray (#CCCCCC).

col.border

character string specifying the hexadecimal color code for panel borders. If NULL, panel borders will be removed. Defaults to light gray (#CCCCCC).

Details

Setting any aesthetic to NA will use the default value. For most values, this means the aesthetic will be blank or not appear on the horizon plot. Other values like xlabel will use their default text. If an aesthetic is already in the horizon plot by default, and you want to remove it, you can do so by setting the respective argument to NULL.

This function provides an easy way to add the most common aesthetics to the horizon plot, but if you want to add other aesthetics not included in this function, you can do so by appending them to the horizon plot object using the + operator. e.g. to add a gray background in the plotting area:
horizonplot(prepanel(otudata = otusample_diet, metadata = metadatasample_diet, taxonomydata = taxonomysample_diet, subj = "MCTs01")) + theme(panel.background = element_rect(fill="gray90"))

Value

A list containing custom ggplot aesthetics to override default values on the horizon plot. This list can then be supplied to horizonplot() to apply the aesthetics.

Examples

plist <- prepanel(otudata = otusample_diet, metadata = metadatasample_diet, 
taxonomydata = taxonomysample_diet, subj = "MCTs01")

# By default, the function is called with no arguments to use default aesthetics
horizonplot(plist, horizonaes())

# Same plot as above
horizonplot(plist)

# Add a custom title, ylabel
horizonplot(plist, horizonaes(title = "Microbiome Horizon Plot", ylabel = "OTU ID"))

# Remove the default x-label
horizonplot(plist, xlabel = NULL)

# Use a different colorscale
library(RColorBrewer)
horizonplot(plist, horizonaes(col.bands = brewer.pal(8, "PiYG")))

# To add aesthetics not included in this function, append them to the
# horizon plot object. e.g. for a gray plotting area background:
horizonplot(plist) + theme(panel.background = element_rect(fill = "gray90"))


blekhmanlab/biomehorizon documentation built on Nov. 8, 2023, 12:16 a.m.