gl.pcoa.plot: Bivariate or trivariate plot of the results of an ordination...

View source: R/gl.pcoa.plot.r

gl.pcoa.plotR Documentation

Bivariate or trivariate plot of the results of an ordination generated using gl.pcoa()

Description

This script takes output from the ordination generated by gl.pcoa() and plots the individuals classified by population.

Usage

gl.pcoa.plot(
  glPca,
  x,
  scale = FALSE,
  ellipse = FALSE,
  plevel = 0.95,
  pop.labels = "pop",
  interactive = FALSE,
  as.pop = NULL,
  hadjust = 1.5,
  vadjust = 1,
  xaxis = 1,
  yaxis = 2,
  zaxis = NULL,
  pt.size = 2,
  pt.colors = NULL,
  pt.shapes = NULL,
  label.size = 1,
  axis.label.size = 1.5,
  plot.display = TRUE,
  plot.theme = theme_dartR(),
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

glPca

Name of the PCA or PCoA object containing the factor scores and eigenvalues [required].

x

Name of the genlight object or fd object containing the SNP genotypes or Tag P/A (SilicoDArT) genotypes [required to gain access to metadata].

scale

If TRUE, scale the x and y axes in proportion to % variation explained [default FALSE].

ellipse

If TRUE, display ellipses to encapsulate points for each population [default FALSE].

plevel

Value of the percentile for the ellipse to encapsulate points for each population [default 0.95].

pop.labels

How labels will be added to the plot ['none'|'ind'|'pop'|'legend', default = 'pop'].

interactive

If TRUE then the populations are plotted without labels, mouse-over to identify points [default FALSE].

as.pop

Assign another metric to represent populations for the plot [default NULL].

hadjust

Horizontal justification of the label against the point it annotates in 2D plots; 0.5 centres the label on the point, larger values shift it to the left [default 1.5].

vadjust

Vertical justification of the label against the point it annotates in 2D plots; 0.5 centres the label on the point, larger values shift it downward [default 1].

xaxis

Identify the x axis from those available in the ordination (xaxis <= nfactors) [default 1].

yaxis

Identify the y axis from those available in the ordination (yaxis <= nfactors) [default 2].

zaxis

Identify the z axis from those available in the ordination for a 3D plot (zaxis <= nfactors) [default NULL].

pt.size

Specify the size of the displayed points [default 2].

pt.colors

Optionally provide a vector of nPop colors (run gl.select.colors() for color options) [default NULL].

pt.shapes

Optionally provide a vector of nPop shapes (run gl.select.shapes() for shape options); not applied to the 3D plot [default NULL].

label.size

Specify the size of the point labels [default 1].

axis.label.size

Specify the size of the displayed axis labels [default 1.5].

plot.display

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

plot.theme

Theme for the plot [default theme_dartR()].

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()].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default 2 or as specified using gl.set.verbosity].

Details

The factor scores are taken from the output of gl.pcoa() and the population assignments are taken from from the original data file. In the bivariate plots, the specimens are shown optionally with adjacent labels and enclosing ellipses. Population labels on the plot are shuffled so as not to overlap (using package {directlabels}). This can be a bit clunky, as the labels may be some distance from the points to which they refer, but it provides the opportunity for moving labels around using graphics software (e.g. Adobe Illustrator). Labels are selected with pop.labels – 'pop' labels each cluster of points with its population name, 'ind' labels each point with its individual name, 'legend' identifies populations in a legend beside the plot, and 'none' plots the points alone. The hadjust and vadjust parameters set the justification of those labels against the point they annotate. 3D plotting is activated by specifying a zaxis. Any pair or trio of axes can be specified from the ordination, provided they are within the range of the nfactors value provided to gl.pcoa(). In the 2D plots, axes can be scaled to represent the proportion of variation explained. In any case, the proportion of variation explained by each axis is provided in the axis label. Colors and shapes of the points can be altered by passing a vector of shapes and/or a vector of colors. These vectors can be created with gl.select.shapes() and gl.select.colors() and passed to this script using the pt.shapes and pt.colors parameters. Shapes are not available in the 3D plot. Points displayed in the ordination can be identified if the option interactive=TRUE is chosen, in which case the resultant plot is ggplotly() friendly. Identification of points is by moving the mouse over them. Refer to the plotly package for further information. The interactive option is automatically enabled for 3D plotting.

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 plot object – a ggplot for the 2D plots, a plotly htmlwidget for the interactive and 3D plots, and a gganimate object for an ordination of a list of simulated generations. The object is returned visibly, so an unassigned call renders the plot.

Author(s)

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

See Also

gl.pcoa

Examples

if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
 test <- gl.pcoa(platypus.gl)
 gl.pcoa.plot(glPca = test, x = platypus.gl)

# SET UP DATASET
gl <- testset.gl
levels(pop(gl))<-c(rep('Coast',5),rep('Cooper',3),rep('Coast',5),
rep('MDB',8),rep('Coast',7),'Em.subglobosa','Em.victoriae')
# RUN PCA
pca<-gl.pcoa(gl,nfactors=5)
# VARIOUS EXAMPLES
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.95, pop.labels='pop',
axis.label.size=1, hadjust=1.5,vadjust=1)
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.99, pop.labels='legend',
axis.label.size=1)
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.99, pop.labels='legend',
axis.label.size=1.5,scale=TRUE)
gl.pcoa.plot(pca, gl, ellipse=TRUE, axis.label.size=1.2, xaxis=1, yaxis=3,
scale=TRUE)
gl.pcoa.plot(pca, gl, pop.labels='none',scale=TRUE)
#gl.pcoa.plot(pca, gl,  interactive=TRUE)
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.99, xaxis=1, yaxis=2, zaxis=3)
# COLOR AND SHAPE ADJUSTMENTS
shp <- gl.select.shapes(select=c(16,17,17,0,2))
col <- gl.select.colors(library='brewer',palette='Spectral',ncolors=11,
select=c(1,9,3,11,11))
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.95, pop.labels='pop',
pt.colors=col, pt.shapes=shp, axis.label.size=1, hadjust=1.5,vadjust=1)
gl.pcoa.plot(pca, gl, ellipse=TRUE, plevel=0.99, pop.labels='legend',
 pt.colors=col, pt.shapes=shp, axis.label.size=1)
# DISTANCE MATRIX
 D <- gl.dist.ind(gl)
 pco <- gl.pcoa(D)
 gl.pcoa.plot(pco,gl,ellipse=TRUE)
 

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