dapc_plot: Plot DAPC results

View source: R/dapc_plot.R

dapc_plotR Documentation

Plot DAPC results

Description

Plot the results of a DAPC. Includes options to produce scatterplot, probability plots, and correct assignment heat maps. Expects output produced from the function genomalicious::dapc_fit.

Usage

dapc_plot(
  dapcList,
  type,
  plotLook = "ggplot",
  axisIndex = NULL,
  popBarScale = 1,
  sampleShow = TRUE,
  sampleOrder = "by_id",
  plotColours = NULL,
  legendPos = "top"
)

Arguments

dapcList

List: A list object generated from genomalicious::dapc_fit. See details.

type

Character: The type of plot to produce. If 'scatter', a scatter plot is produced. If 'scree', a screeplot of the explained among-population variation is produced. If 'cumvar', a plot of the cumulative explained among-population variation is produced. If 'probs', a plot of posterior probability for populations identity is produced. If 'assign', a heatmap of assignment rates among population pairs is produced.

plotLook

Character: The plot theme, only applicable when type=='scatter'. Default = 'ggplot', the typical gray background with gridlines produced by ggplot2. Alternatively, when set to 'classic', produces a base R style plot.

axisIndex

Integer: The LD axes to plot. If type=='scatter', there must be exactly 2 values, the two LD axes to plot as a scatterplot. If type=='scree' or type=='cumvar', these are the axes for which you want to see the explained or cumulative among-population variance, respectively. Default is NULL.

popBarScale

Numeric: A scaling value for the population guide bar, only applicable when type=='probs'. A guide bar is used to delineate the original designated populations. The thickness of this bar is controlled with popBarScale. Default is 1, and the value must be >= 1.

sampleShow

Logical: Should the sample names be displayed in the probability plot? Only applicable when type=='probs'. Default is TRUE.

sampleOrder

Logical: Should the samples be ordered by their IDs ('by_id') or by their estimated probability ('by_probs') in the probability plot? Only applicable when type=='probs'. Default is 'by_id'.

plotColours

Character: A vector of colours to use. If type=='scatter' or type=='probs', then this needs to be a named vector, where the values are colours and their indexed names are populations. All populations need to be represented with a colour. If type=='assign', a series of colours needs to be specified to parameterise the colour gradient in the assignment rate heatmap. If type=='scree' or type=='cumvar', a single value.

legendPos

Character: Where should the legend be positioned? Default is 'top', but could also be one of, 'right', 'bottom', 'left', or 'none'.

Details

If you want to produce a DAPC scatterplot (type=='scatter') or a probability plot (type=='probs'), then this function receives the output of dapc_fit(..., type='fit'). If instead, you have performed as assignment analysis with dapc_fit(..., type='loo_cv') or dapc_fit(..., type='traint_test'), then you want to parameterise with type=='assign'.

In the probability plot is requested (type=='probs'), you can choose to order samples by their estimated probabilities for their designated population by setting sampleOrder='by_probs'. The default is sampleOrder='by_id', in which case, samples are ordered alpha-numerically by populations and their sample ID, i.e., the command: data.table::setorder(.., POP, SAMPLE).

Value

Returns a ggplot object.

Examples

library(genomalicious)

data("data_Genos")

# DAPC fit on all samples
DAPC.fit <- dapc_fit(data_Genos, pcPreds=3, method='fit')

# DAPC using training and testing partitions
DAPC.tt <- dapc_fit(data_Genos, pcPreds=3, method='train_test')

# Scatterplot, LD1 and LD2, with default colours, and ggplot look
dapc_plot(DAPC.fit, type='scatter', axisIndex=c(1,2))

# Scatterplot, LD2 and LD3, with manual colours, and classic look
dapc_plot(DAPC.fit, type='scatter', axisIndex=c(2,3), plotLook='classic',
plotColours=c(Pop1='#08c7e0', Pop2='#4169e1', Pop3='#e46adf', Pop4='#ce0073')
)

# Screeplot
dapc_plot(DAPC.fit, type='scree', )

# Probability plot, default colours
dapc_plot(DAPC.fit, type='probs')

# Probability plot, manual colours, population bar rescaled, sample names
turned off, and legend turned off.
dapc_plot(DAPC.fit, type='probs', popBarScale=5,
plotColours=c(Pop1='#08c7e0', Pop2='#4169e1', Pop3='#e46adf', Pop4='#ce0073'),
sampleShow=FALSE, legendPos='none'
)

# Assignment heatmap, default colours
dapc_plot(DAPC.tt, type='assign')

# Assignment heatmap, manual colours, and legend repositioned to top
dapc_plot(DAPC.tt, type='assign', plotColours=c('white', 'grey50', 'grey20'),
legendPos='top')


j-a-thia/genomalicious documentation built on Oct. 19, 2024, 7:51 p.m.