plot_pca.trajectories: Plot trajectories based on Temporal Check-All-That-Apply...

Description Usage Arguments References See Also Examples

View source: R/tcata.R

Description

Plot trajectories following PCA on multiblock TCATA proportions, or same for Temporal Dominance of Sensations (TDS) proportions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
plot_pca.trajectories(in.pca = in.pca, products.times = matrix(NA),
attributes = c(), type = "smooth", span = 0.75, biplot = "distance",
flip = c(FALSE, FALSE), dims = c(1, 2),
att.offset.x = c(), att.offset.y = c(), inflate.factor = NA,
xlab = "_auto_", ylab = "_auto_", xlim = NULL, ylim = NULL,
attributes.col = "red", attributes.pch = 17,
lwd = 1, traj.lab.loc = 0, traj.col = c(grDevices::grey(1/2)), traj.points = NA,
traj.col.seg = NA, traj.cex = 1, traj.lab = c(), traj.lab.cex = 1,
arrow.loc = NA, arrow.length = 0.1, arrow.col = NA, arrow.lwd = NA,
contrails = list(), main = "", save.format = "eps", save.as = "")

Arguments

in.pca

Any list object with components sdev, rotation, and x. Most often it is a prcomp object obtained from PCA on a matrix of proportions (or, if there is no missing data, on counts) with Product*Times in rows and Attributes in columns.

products.times

a 2-column matrix, with an ascending sort order on products (column 1) and a secondary ascending sort on times (column 2), corresponding to the rows of the matrix submitted to prcomp to obtain "in.pca".

attributes

a vector of attribute labels, corresponding to the attributes of the matrix submitted to prcomp to obtain "in.pca".

type

Determines how trajectories are drawn. Possible values are "smooth" (default) or "raw".

span

A tuning parameter used if smoothing trajectories using the loess function.

biplot

Controls the type of biplot displayed. Possible values are "distance" (plots trajectories based on scores, and attributes based on eigenvectors multiplied by the "inflation.factor"), or "correlation" (plots trajectories based on scores divided by the sqrt of their respective eigenvalues, and attributes based on eigenvectors multiplied by the sqrt of their respective eigenvalues).

flip

a vector of two logical values. Value indicates whether to mirror the coordinates in the x and y dimensions respectively. Default is c(FALSE, FALSE).

dims

a vector of two integers, specifying the principal componts to display. Defaults is "c(1, 2)", i.e. PC1 vs. PC2.

att.offset.x

A vector of numeric values corresponding to the labels in "attributes". Used to adjust the horizontal position of attribute labels to make the plot more readable.

att.offset.y

A vector of numeric values corresponding to the labels in "attributes". Used to adjust the vertical position of attribute labels to make the plot more readable.

inflate.factor

Scalar controlling the position of attribute labels. If "NA" (default), then this scalar is set to the largest absolute score divided by the largest absolute eigenvector based on the dimensions used. Use "1" for no inflation. Applies only when biplot = "distance".

xlab

Label for x axis.

ylab

Label for y axis.

xlim

Permits control of the x limit. Limits can be specified using a vector of 2 (ascending) numbers. If a single number is provided then values are selected such that the limits are 20% beyond the smallest and largest x coordinates, respectively. If unspecified then control over x axis limits is given to the plot function in R.

ylim

Permits control of the x limit using the same logic as is used for "xlim".

attributes.col

Color used to display attribute labels (see "attributes").

attributes.pch

Symbol for attribute coordinates.

lwd

Trajectory line width.

traj.lab.loc

Indicates where along the trajectory the trajectory label will be positioned. "1" indicates the start of the trajectory. The value "0" (default) is a special convention indicating the end of the trajectory.

traj.col

A vector of colors for trajectories. If not specified then all trajectories are shown in grey.

traj.points

Specifies the position of markers along smoothed trajectories, and used to indicate the progression of time.

traj.col.seg

A vector of colors for segments along trajectories. If NA (default) then no segments along the trajectories appear in a color other than those specified by "traj.col". This parameter applies to smoothed trajectories only.

traj.cex

Used with "traj.points" for smoothed trajectories. Controls the size of symbol displayed.

traj.lab

A vector of character labels that identify the trajectories. If unspecified, then products are identified by ascending natural numbers.

traj.lab.cex

Text size of traj.lab.

arrow.loc

Trajectory arrows locations for direction marker(s).

arrow.length

Trajectory arrows length. See length parameter in arrows.

arrow.col

Trajectory arrows color. See col parameter in arrows.

arrow.lwd

Trajectory arrows line width. See lwd parameter in arrows.

contrails

list of data.frame objects with columns x, y, count, col; x and y are coordinates, count is the number of values at the coordinate, and col is the rbg colour.

main

plot title; see plot.

save.format

If indicated, this will be the file type for the save image. Defaults to "eps" (eps format). Other possible values are "" (not saved) or "png" (png format).

save.as

The filename. Must be provided if the file will be saved.

References

Castura, J.C., AntĂșnez, L., GimĂ©nez, A., Ares, G. (2016). Temporal check-all-that-apply (TCATA): A novel temporal sensory method for characterizing products. Food Quality and Preference, 47, 79-90. http://dx.doi.org/10.1016/j.foodqual.2015.06.017

Castura, J.C., Baker, A.K., & Ross, C.F. (2016). Using contrails and animated sequences to visualize uncertainty in dynamic sensory profiles obtained from temporal check-all-that-apply (TCATA) data. Food Quality and Preference, 54, 90-100. http://dx.doi.org/10.1016/j.foodqual.2016.06.011

See Also

prcomp, par

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# example using 'syrah' data set
syrah.pca <- prcomp(syrah[1:248, -c(1:4)], scale. = FALSE)
plot_pca.trajectories(syrah.pca, products.times = syrah[1:248, c(1, 4)],
                      attributes = colnames(syrah)[-c(1:4)], type = "raw")

# now with smoothing; may need to play with the span parameter to get appropriate smoothing
plot_pca.trajectories(syrah.pca, products.times = syrah[1:248, c(1, 4)],
                      attributes = colnames(syrah)[-c(1:4)], type = "smooth", span = 0.3)

# plots at each time point (trajectories join 2 points so start at timepoint 2, i.e., 11 s)
x <- 11:14 # for brevity show only the first 4 timeslices
# x <- 11:41 # uncomment this line to to run a longer demo
pca.list <- list()
for(i in seq_along(x)){
  pca.list[[x[i]-10]] <- syrah.pca
  pca.list[[x[i]-10]]$x <- pca.list[[x[i]-10]]$x[1:((x[i]-9)*6), ]
  plot_pca.trajectories(pca.list[[x[i]-10]], products.times = syrah[1:((x[i]-9)*6), c(1, 4)],
                        attributes = colnames(syrah)[-c(1:4)], type = "raw", inflate.factor = 1.5)
  Sys.sleep(3/4)
  # save plot if saving stills for a video; see Castura, Baker, & Ross (2016, Video 1)
}

tempR documentation built on Jan. 9, 2020, 1:09 a.m.