plot_popkin {popkin} | R Documentation |
This function plots one or more kinship matrices and a shared legend for the color key. Many options allow for fine control of individual or subpopulation labeling. This code assumes input matrices are symmetric.
plot_popkin(kinship, titles = NULL, col = NULL, col_n = 100, mar = NULL, mar_pad = 0.2, diag_line = FALSE, panel_letters = toupper(letters), panel_letters_cex = 1.5, ylab = "Individuals", ylab_adj = NA, ylab_line = 0, layout_add = TRUE, layout_rows = 1, leg_title = "Kinship", leg_cex = 1, leg_mar = NULL, leg_n = 5, names = FALSE, names_cex = 1, names_line = NA, labs = NULL, labs_cex = 1, labs_las = 0, labs_line = 0, labs_sep = TRUE, labs_lwd = 1, labs_col = "black", labs_ticks = FALSE, labs_text = TRUE, labs_even = FALSE, ...)
kinship |
A numeric kinship matrix or a list of matrices.
Note |
titles |
Titles to add to each matrix panel (default is no titles) |
col |
Colors for heatmap (default is a red-white-blue palette symmetric about zero constructed using RColorBrewer). |
col_n |
The number of colors to use in the heatmap (applies if |
mar |
Margins for each panel (if a list) or for all panels (if a vector).
Margins are in |
mar_pad |
Margin padding added to all panels ( |
diag_line |
If |
panel_letters |
Vector of strings for labeling panels (default A-Z).
No labels are added if |
panel_letters_cex |
Scaling factor of panel letters (default 1.5). AXIS LABEL OPTIONS |
ylab |
The y-axis label (default "Individuals").
If |
ylab_adj |
The value of "adj" passed to |
ylab_line |
The value of "line" passed to LAYOUT OPTIONS |
layout_add |
If |
layout_rows |
Number of rows in layout, used only if LEGEND (COLOR KEY) OPTIONS |
leg_title |
The name of the variable that the heatmap colors measure (default "Kinship"). |
leg_cex |
Scaling factor for |
leg_mar |
Margin vector (in |
leg_n |
The desired number of ticks in the legend y-axis (input to INDIVIDUAL LABEL OPTIONS |
names |
If |
names_cex |
Scaling factor for the column and row names. |
names_line |
Line where column and row names are placed. SUBPOPULATION LABEL OPTIONS |
labs |
Subpopulation labels for individuals. Use a matrix of labels to show groupings at more than one level (for a hierarchy or otherwise). If input is a vector or a matrix, the same subpopulation labels are shown for every heatmap panel; the input must be a list of such vectors or matrices if the labels vary per panel. |
labs_cex |
A vector of label scaling factors for each level of labs, or a list of such vectors if labels vary per panel. |
labs_las |
A vector of label orientations (in format that |
labs_line |
A vector of lines where labels are placed (in format that |
labs_sep |
A vector of booleans that specify whether lines separating the subpopulations are drawn for each level of labs, or a list of such vectors if labels vary per panel. |
labs_lwd |
A vector of line widths for the lines that divide subpopulations (if |
labs_col |
A vector of colors for the lines that divide subpopulations (if |
labs_ticks |
A vector of booleans that specify whether ticks separating the subpopulations are drawn for each level of labs, or a list of such vectors if labels vary per panel. |
labs_text |
A vector of booleans that specify whether the subpopulation labels are shown for each level of labs, or a list of such vectors if labels vary per panel. Useful for including separating lines or ticks without text. |
labs_even |
A vector of booleans that specify whether the subpopulations labels are drawn with equal spacing for each level of labs, or a list of such vectors if labels vary per panel.
When |
... |
Additional options passed to |
plot_popkin
plots the input kinship matrices as-is.
For best results, a standard kinship matrix (such as the output of popkin
) should have its diagonal rescaled to contain inbreeding coefficients (inbr_diag
does this) before plot_popkin
is used.
This function permits the labeling of individuals (from row and column names when names = TRUE
) and of subpopulations (passed through labs
).
The difference is that the labels passed through labs
are assumed to be shared by many individuals, and lines (or other optional visual aids) are added to demarcate these subgroups.
# Construct toy data X <- matrix(c(0,1,2,1,0,1,1,0,2), nrow = 3, byrow = TRUE) # genotype matrix subpops <- c(1,1,2) # subpopulation assignments for individuals # NOTE: for BED-formatted input, use BEDMatrix! # "file" is path to BED file (excluding .bed extension) ## library(BEDMatrix) ## X <- BEDMatrix(file) # load genotype matrix object # estimate the kinship matrix from the genotypes "X"! kinship <- popkin(X, subpops) # calculate kinship from X and optional subpop labels # simple plot of the kinship matrix, marking the subpopulations only # note inbr_diag replaces the diagonal of kinship with inbreeding coefficients # (see vignette for more elaborate examples) plot_popkin( inbr_diag(kinship), labs = subpops )