Description Usage Arguments Details Author(s) Examples
This function is implemented in the unique function 'plot.pca'. It generated and visualizes PCA score plot color-coded according with the class definition in the second column of the file. This function cannot be used without having previously used the function 'explore.data'.
1 | Plot.pca.score(pcx, pcy, scaling)
|
pcx |
an integer indicating the principal component to be plotted in x. |
pcy |
an integer indicating the principal component to be plotted in y |
scaling |
a character string indicating the name of the scaling previously specified in the function 'explore.data' |
For details see ?plot.pca.
Edoardo Gaude, Dimitrios Spiliotopoulos, Francesca Chignola, Silvia Mari, Andrea Spitaleri and Michela Ghitti
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ## The function is currently defined as
function (pcx, pcy, scaling)
{
score = paste(getwd(), "/PCA_Data_", scaling, "/PCA_ScoreMatrix.csv",
sep = "")
ppppp = paste(getwd(), "/PCA_Data_", scaling, "/PCA_P", sep = "")
Score <- read.csv(score, sep = ",", header = TRUE)
Score.x <- Score[, 2:ncol(Score)]
rownames(Score.x) <- Score[, 1]
pwdK = paste(getwd(), "/Preprocessing_Data_", scaling, "/class.csv",
sep = "")
k = read.csv(pwdK)
Pvar <- read.csv(ppppp, sep = ",", header = TRUE)
Pvar.x <- Pvar[, 2:ncol(Pvar)]
rownames(Pvar.x) <- Pvar[, 1]
pca <- paste("PC", pcx, " (", Pvar[pcx, 2], ") %")
pcb <- paste("PC", pcy, " (", Pvar[pcy, 2], ")%")
cum = Pvar[pcx, 2] + Pvar[pcy, 2]
xlab = c(pca)
ylab = c(pcb)
lim = c()
max.pc1 = 1.3 * (max(abs(Score.x[, pcx])))
max.pc2 = 1.3 * (max(abs(Score.x[, pcy])))
if (max.pc1 > max.pc2) {
lim = c(-max.pc1, max.pc1)
}
else {
lim = c(-max.pc2, max.pc2)
}
tutticolors = matrix(c(1, 2, 3, 4, 5, 6, 7, 8, "rosybrown4",
"green4", "navy", "purple2", "orange", "pink", "chocolate2",
"coral3", "khaki3", "thistle", "turquoise3", "palegreen1",
"moccasin", "olivedrab3", "azure4", "gold3", "deeppink"),
ncol = 1)
col = c()
for (i in 1:nrow(k)) {
col = c(col, tutticolors[k[i, 2], ])
}
dev.new()
plot(Score.x[, pcx], Score.x[, pcy], col = col, xlab = xlab,
ylab = ylab, xlim = lim, ylim = lim, pch = 19, sub = paste("Cumulative Proportion of Variance Explained = ",
cum, "%", sep = ""), main = paste("PCA Score Plot (",
scaling, ")", sep = ""))
axis(1, at = lim * 2, pos = c(0, 0), labels = FALSE, col = "grey",
lwd = 0.7)
axis(2, at = lim * 2, pos = c(0, 0), labels = FALSE, col = "grey",
lwd = 0.7)
library(car)
dataEllipse(Score.x[, pcx], Score.x[, pcy], levels = c(0.95),
add = TRUE, col = "black", lwd = 0.4, plot.points = FALSE,
center.cex = 0.2)
text(Score.x[, pcx], Score.x[, pcy], col = col, cex = 0.5,
labels = rownames(Score.x), pos = 1)
D <- paste(getwd(), "/PCA_Data_", scaling, "/ScorePlot_PC",
pcx, "vsPC", pcy, ".pdf", sep = "")
dev.copy2pdf(file = D)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.