gl.filter.factorloadings: Filters loci based on factor loadings for a PCA or PCoA

View source: R/gl.filter.factorloadings.r

gl.filter.factorloadingsR Documentation

Filters loci based on factor loadings for a PCA or PCoA

Description

Extracts the factor loadings from a glPCA object (generated by gl.pcoa) and filters loci based on a user specified threshold for the ABSOLUTE value of the factor loadings.

Usage

gl.filter.factorloadings(
  x,
  pca,
  axis = 1,
  threshold,
  retain = FALSE,
  plot.display = TRUE,
  plot.theme = theme_dartR(),
  plot.colors = NULL,
  plot.file = NULL,
  plot.dir = NULL,
  bins = 25,
  verbose = NULL,
  ...
)

Arguments

x

Name of the genlight object containing the SNP data or the SilocoDArT data [required].

pca

Name of the glPCA object containing factor loadings [required].

axis

Axis in the ordination used to display the factor loadings [default 1]

threshold

Numeric value for the factor loadings. This value is the ABSOLUTE value of the factor loadings [required].

retain

If true, the resultant genlight object holds only the loci that load high on the specified axis; if FALSE, the resultant genlight object has the loci loading high on the specified axis filtered out [default FALSE].

plot.display

If TRUE, resultant plots are displayed in the plot window [default TRUE].

plot.theme

Theme for the plot. See Details for options [default theme_dartR()].

plot.colors

List of two color names for the borders and fill of the plots [default c("#2171B5","#6BAED6")].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL]

plot.dir

Directory to save the plot RDS files [default as specified by the global working directory or tempdir()]

bins

Number of bins to display in histograms [default 25].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, adopting the global verbosity set by gl.set.verbosity(), or 2 if no global is set].

...

Parameters passed to function ggsave, such as width and height, when the ggplot is to be saved.

Details

The function extracts the factor loadings for a given axis from a PCA object generated by gl.pcoa and then filters loci on the basis of a user specified threshold. The threshold value is decided using gl.report.factorloadings. The function can be used to filter out loci that load high with a particular axis or alternatively if retain=TRUE, to retain loci that load high on a specified axis.

Note that this function also removes monomorphic loci because PCA is performed only on polymorphic loci.

The pca object must have been generated from the same genlight object as is passed to this function; the function stops if the number of loadings does not match the number of polymorphic loci.

A color vector can be obtained with gl.select.colors() and then passed to the function with the plot.colors parameter.

Themes can be obtained from in

If a plot.file is given, the ggplot arising from this function is saved as an "RDS" binary file using saveRDS(); can be reloaded with readRDS(). A file name must be specified for the plot to be saved. If a plot directory (plot.dir) is specified, the ggplot binary is saved to that directory; otherwise to the tempdir().

Value

The filtered genlight object, returned invisibly.

Author(s)

Author(s): Arthur Georges. Custodian: Arthur Georges – Post to https://groups.google.com/d/forum/dartr

See Also

Other matched filter: gl.filter.allna(), gl.filter.callrate(), gl.filter.contamination(), gl.filter.excess.het(), gl.filter.hamming(), gl.filter.heterozygosity(), gl.filter.hwe(), gl.filter.ld(), gl.filter.locmetric(), gl.filter.maf(), gl.filter.monomorphs(), gl.filter.overshoot(), gl.filter.pa(), gl.filter.rdepth(), gl.filter.replicates(), gl.filter.replicates.KING(), gl.filter.reproducibility(), gl.filter.secondaries(), gl.filter.taglength()

Examples

if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
pca <- gl.pcoa(testset.gl)
gl.report.factorloadings(pca = pca)
gl2 <- gl.filter.factorloadings(pca=pca,x=testset.gl,threshold=0.2)


dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.