Código
<- matrix(nrow=10, ncol=8)
data.matrix colnames(data.matrix) <- c(
paste("TS", 1:4, sep=""),
paste("TR", 1:4, sep="")
)rownames(data.matrix) <- paste("planta", 1:10, sep="")
for (i in 1:10) {
<- rpois(4, lambda = sample(x=0:150, size=1))
wt.values <- rpois(4, lambda = sample(x=0:150, size=1))
ko.values
<- c(wt.values, ko.values)
data.matrix[i,]
}
head(data.matrix)
TS1 TS2 TS3 TS4 TR1 TR2 TR3 TR4
planta1 86 79 79 76 143 102 127 144
planta2 8 7 15 8 126 120 116 135
planta3 142 134 139 132 85 81 71 71
planta4 103 102 74 79 95 99 108 107
planta5 11 11 8 11 110 117 112 107
planta6 70 51 60 48 52 68 71 68
Código
<- prcomp(t(data.matrix), scale = TRUE)
pca
plot(pca$x[,1], pca$x[,2])
Código
<- pca$sdev^2
pca.var <- round(pca.var/sum(pca.var)*100,1)
pca.var.per
barplot(pca.var.per, main ="Scree plot", xlab="Principal component", ylab = "Percent of Variation")
<- data.frame(Sample=rownames(pca$x),
pca.data X=pca$x[,1],
Y=pca$x[,2])
library(ggplot2)
Código
<- ggplot(data=pca.data, aes(x=X, y=Y, label=Sample)) +
gg.PCA geom_text() +
xlab(paste("PC1 - ", pca.var.per[1], "%", sep=""))+
ylab(paste("PC2 - ", pca.var.per[2], "%", sep=""))+
theme_bw()+
ggtitle("My PCA Graph")
<- pca$rotation[,1]
loading_scores <- abs(loading_scores)
planta_scores <- sort(planta_scores, decreasing = TRUE)
planta_scores_ranked
<- names(planta_scores_ranked[1:10])
top_10_plantas
$rotation[top_10_plantas, 1] pca
planta5 planta2 planta3 planta1 planta8 planta10 planta9
-0.3724079 -0.3701929 0.3665763 -0.3434550 0.3381103 0.3322800 -0.2928192
planta7 planta4 planta6
-0.2749108 -0.2300509 -0.1815461
Código
### pruebas con 3d
gg.PCA
Código
library(rayshader)
plot_gg(gg.PCA, multicore = TRUE, width = 5, height = 5,
scale = 200, windowsize=c(1280,720),
zoom = 0.60, phi = 50, sunangle = 120, theta = 45)
render_snapshot()