plotxy: 2-d scatter plot

View source: R/plotxy.R

plotxyR Documentation

2-d scatter plot

Description

2-dimension scatter plot.

Usage

plotxy(X, asp = 1, col = NULL, alpha.f = .8,
  group = NULL, legend = TRUE, legend.title = NULL, ncol = 1,
  zeroes = FALSE, circle = FALSE, ellipse = FALSE,
  labels = FALSE,
  ...)

Arguments

X

A n x p matrix or data frame. If p > 2, only the first two columns are considered.

asp

Scalar. Giving the aspect ratio y/x. The value asp = 0 is the default in plot.default (no constraints on the ratio). See plot.default.

col

A color, or a vector of colors (of length equal to the number of groups), defining the color(s) of the points.

alpha.f

Scalar modifying the opacity of the points in the graphics; typically in [0,1]. See adjustcolor.

group

A vector of length n defining groups of observations to be plotted with different colors (default to NULL).

legend

Only if there are groups. Logical indicationg is a legend is drawn for groups (Default to FALSE).

legend.title

Character string indicationg a title for the legend.

ncol

Number of columns drawn in the legend box.

zeroes

Logical indicationg if an horizontal and vertical lines are drawn at coordonates (0, 0) (Default to FALSE).

circle

Logical indicating if a correlation circle (see examples in pls) is plotted (default to FALSE).

ellipse

Logical indicating if a Gaussian ellipse is plotted (default to FALSE). If there are groups, an ellipse is drawn for each group.

labels

Logical indicating if the row names of X (instead of points) are plotted (default to FALSE).

...

Other arguments to pass in functions plot, points, axis and text.

Value

A plot.

Examples


data(datcass)

Xr <- datcass$Xr
yr <- datcass$yr
Xu <- datcass$Xu
yu <- datcass$yu

ncomp <- 5
fm <- pca(Xr, Xu, ncomp = ncomp)
names(fm)
Tr <- fm$Tr
Tu <- fm$Tu
cor.circle <- fm$cor.circle
coord.var <- fm$coord.var
headm(Tr)
headm(Tu)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotxy(Tr[, 1:2])
plotxy(Tr[, 3:4], pch = 16, ellipse = TRUE)
par(oldpar)

T <- rbind(Tr, Tu)
group <- c(rep("Reference", nrow(Tr)), rep("Unknown", nrow(Tu)))
oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotxy(T, group = group, pch = 16, ellipse = TRUE)
plotxy(T[, 3:4], group = group, pch = 16)
par(oldpar)

### See: ?hcl.colors, hcl.pals()
group <- 1:nrow(Tr)
col <- hcl.colors(n = length(group), alpha = .5, rev = FALSE, palette = "Blues")
plotxy(Tr, group = group, col = col, legend = FALSE, pch = 16)

############## FICTIVE PCA EXAMPLE

n <- 10 ; p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
set.seed(NULL)
Xr <- X[1:8, ]
Xu <- X[9:10, ] 
fm <- pca(Xr, Xu, ncomp = ncomp)
Tr <- fm$Tr
Tu <- fm$Tu
P <- fm$P

T <- rbind(Tr, Tu)
row.names(T) <- 1:nrow(T)
group <- c(rep("Reference", nrow(Tr)), rep("Unknown", nrow(Tu)))
plotxy(T, group = group, pch = 16, zeroes = TRUE)

plotxy(T, group = group, labels = TRUE, zeroes = TRUE)

plotxy(P, zeroes = TRUE, labels = TRUE)

plotxy(fm$coord.var, zeroes = TRUE, labels = TRUE)

plotxy(fm$cor.circle, zeroes = TRUE, labels = TRUE, circle = TRUE, ylim = c(-1, 1))

############## EXTERNAL RESIZED WINDOW

Xr <- datcass$Xr
fm <- pca(Xr, ncomp = 4)

## Do as below (removing comments '#'):

#windows(width = 7, height = 6)
#plotxy(Tr)
#dev.off()


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.