plotMatrix {distantia}R Documentation

Plots distance matrices and least cost paths.

Description

Plots the output matrices of distanceMatrix and leastCostMatrix, and superimposes the least cost path generated by leastCostPath. This functions relies on image.plot to plot a color scale along with the matrix plot, or image when a color scale is not needed.

Usage

plotMatrix(
  distance.matrix = NULL,
  least.cost.path = NULL,
  plot.columns = NULL,
  plot.rows = NULL,
  legend = TRUE,
  color.palette = "divergent",
  path.color = "black",
  path.width = 1,
  margins = c(2,3,2,4),
  pdf.filename = NULL,
  pdf.width = 7,
  pdf.height = 4,
  pdf.pointsize = 12,
  rotate = FALSE
  )

Arguments

distance.matrix

numeric matrix or list of numeric matrices either produced by distanceMatrix or leastCostMatrix.

least.cost.path

dataframe or list of fdataframes produced by leastCostPath. If a list, must have the same number of slots as distance.matrix.

plot.columns

number of columns of the output plot if the inputs are lists. If not provided, it is computed automatically by n2mfrow.

plot.rows

number of rows of the output plot if the inputs are lists. If not provided, it is computed automatically by n2mfrow.

legend

boolean. If TRUE, the plot is made with image.plot, and includes a color scale on the right side. If FALSE, the plot is made with image, and the color scale is omitted.

color.palette

string defining the color palette to be used, or a color palette. Accepted strings are "divergent" (default), which uses a red-white-blue divergent palette produced by the code colorRampPalette(rev(RColorBrewer::brewer.pal(9, "RdBu")))(100), and "viridis", which uses the default settings of the viridis function to generate the palette. Both settings are color-blind friendly.

path.color

string, color of the line representing the least cost path if least.cost.path is provided.

path.width

line width (lwd) of the plotted path.

margins

a numeric vector with four positions indicating the margins of each plotted matrix. Order of margins in this vector is: bottom, left, top, right.

pdf.filename

character string with the name, without extension, of the pdf to be written. If NULL, no pdf is written.

pdf.width

with in inches of the output pdf. Default value is 7.

pdf.height

height in inches of the output pdf. Default value is 4.

pdf.pointsize

base font size of the output pdf.

rotate

boolean, if TRUE, the matrix is rotated. Allows the user to plot the matrix axes in the desired direction.

Value

A list of dataframes if least.cost.matrix is a list, or a dataframe if least.cost.matrix is a matrix. The dataframe/s have the following columns:

Examples



#loading data
data(sequenceA)
data(sequenceB)

#preparing datasets
AB.sequences <- prepareSequences(
 sequence.A = sequenceA,
 sequence.A.name = "A",
 sequence.B = sequenceB,
 sequence.B.name = "B",
 merge.mode = "complete",
 if.empty.cases = "zero",
 transformation = "hellinger"
 )

#computing distance matrix
AB.distance.matrix <- distanceMatrix(
 sequences = AB.sequences,
 grouping.column = "id",
 method = "manhattan",
 parallel.execution = FALSE
 )

#plot
plotMatrix(distance.matrix = AB.distance.matrix)

#viridis palette
plotMatrix(distance.matrix = AB.distance.matrix,
 color.palette = "viridis")

#custom palette
plotMatrix(distance.matrix = AB.distance.matrix,
color.palette = viridis::viridis(8, option = "B", direction = -1))




[Package distantia version 1.0.2 Index]