Learn R Programming

EEM (version 1.1.1)

plotScore: Plot score for prcomp result

Description

Plot score for prcomp (PCA) result

Usage

plotScore(prcompResult, xPC = 1, yPC = 2, group = NULL, group2 = NULL, cex = 1.5, cex.legend = 1, label = NULL, pos = 4, col = NULL, pch = NULL, legendlocation = "bottomright", legendoutside = FALSE, rightwhitespace = 0, ...)

Arguments

prcompResult
output object from prcomp function
xPC
an integer indicating PC component on x-axis
yPC
an integer indicating PC component on y-axis
group
a vector of numeric, character or factor class separating the samples into groups. Correspond to point color.
group2
The second group, can be a vector of numeric, character or factor class separating the samples into groups. Correspond to point shape.
cex
(optional) size of points on graphs
cex.legend
(optional) size of fonts in legend
label
(optional) a character vector or expression specifying the text to be written.
pos
(optional, applicable when label is given) a position specifier for the text. If specified this overrides any adj value given. Values of 1, 2, 3 and 4, respectively indicate positions below, to the left of, above and to the right of the specified coordinates.
col
point color palette
pch
point type palette
legendlocation
(optional)location of legend on graph. Look up legend for more details.
legendoutside
(optional) set to TRUE if you want to put legend on the outside of the plot. The legend location is defaulted to topright.
rightwhitespace
(optional) set width for white space for legend. Only applicable if legendoutside = TRUE
...
additional arguments for par

Value

A figure is returned on the graphic device

See Also

plotScorem

Examples

Run this code
data(applejuice)
applejuice_uf <- unfold(applejuice) # unfold list into matrix
result <- prcomp(applejuice_uf) 
plotScore(result) # plot PC1 vs PC2 score
plotScore(result, pch = 3, col = "blue") # change shape and color

# get country of apple production
country <- sapply(strsplit(names(applejuice), split = "-"), "[", 1) 
plotScore(result, label = country) # add label

# or plot by group
plotScore(result, xPC = 1, yPC = 3, group = country) 

# custom point types and color
plotScore(result, xPC = 1, yPC = 3, group = country, pch = c(1,2), col = c("green", "black"))

# move legend outside
plotScore(result, xPC = 1, yPC = 3, group = country, legendoutside = TRUE)

# two groups
cultivar <- sapply(strsplit(names(applejuice), split = "-"), "[", 2) 
plotScore(result, group = country, group2 = cultivar)

# make the points more transparent
## Not run: 
# require(scales)
# plotScore(result, group = country, group2 = country, col = alpha(generateColor(2), 0.7))
# ## End(Not run)

Run the code above in your browser using DataLab