scatter_plot {mapmixture} | R Documentation |
PCA or DAPC Scatter Plot
Description
Plot a scatter plot of PCA or DAPC results.
Usage
scatter_plot(
dataframe,
group_ids,
other_group = NULL,
type = "points",
...,
labels = NULL,
axes = c(1, 2),
colours = NULL,
centroids = TRUE,
segments = TRUE,
point_size = 3,
point_type = 21,
centroid_size = 3,
hvline_type = "dotted",
hvline_size = 0.5,
hvline_colour = "black",
xlab = "Axis",
ylab = "Axis",
percent = NULL,
plot_title = ""
)
Arguments
dataframe |
data.frame or tibble containing results from a PCA or DAPC (see examples). |
group_ids |
character vector of IDs representing the group each row belongs to. This is used to colour the scatter plot and (optionally) add centroids and segments. E.g. a vector of site names, a vector of biological categories such as male or female, etc. |
other_group |
secondary character vector of IDs defining how to colour the scatter plot.
E.g. a vector of country names (see examples).
If |
type |
string defining whether to show points ( |
... |
additional arguments passed to |
labels |
character vector of IDs defining labels when |
axes |
integer vector of length two defining which axes to plot. |
colours |
character vector of colours the same length as the number of groups defined in group_ids or other_group. |
centroids |
add centroids to plot ( |
segments |
add segments to plot ( |
point_size |
numeric value for point size. |
point_type |
numeric value for point type (shape). |
centroid_size |
numeric value for centroid label size. |
hvline_type |
integer or string defining linetype ( |
hvline_size |
integer defining linewidth. |
hvline_colour |
string defining line colour. |
xlab |
string defining x axis label. |
ylab |
string defining y axis label. |
percent |
numeric vector the same length as |
plot_title |
string defining the main title of the plot. |
Value
A ggplot object.
Examples
# Results from a Principal Components Analysis
file <- system.file("extdata", "pca_results.csv", package = "mapmixture")
pca_results <- read.csv(file)
# Define parameters
ind_names <- row.names(pca_results)
site_names <- rep(c("Pop1", "Pop2", "Pop3", "Pop4", "Pop5", "Pop6"), each = 100)
region_names <- rep(c("Region1", "Region2"), each = 300)
percent <- c(5.6, 4.5, 3.2, 2.0, 0.52)
# Scatter plot
scatter_plot(pca_results, site_names)
# Scatter plot with axes 1 and 3 and percent on axis labels
scatter_plot(pca_results, site_names, axes = c(1,3), percent = percent)
# Scatter plot with no centroids and segments
scatter_plot(pca_results, site_names, axes = c(1,2), percent = percent,
centroids = FALSE, segments = FALSE)
# Scatter plot with custom colours and coloured by other_group
scatter_plot(pca_results, site_names, other_group = region_names,
percent = percent, colours = c("#f1a340","#998ec3"))
# Scatter plot with individual labels
scatter_plot(pca_results, site_names, type = "labels",
labels = rownames(pca_results))
# Scatter plot with individual text
scatter_plot(pca_results, site_names, type = "text",
labels = rownames(pca_results))