Principal Component analysis (PCA) in R
HTML-код
- Опубликовано: 21 авг 2024
- library("ggplot2")
library("gridExtra")
library(ggbiplot)
library("corrplot")
library(factoextra)
#conversion of row number
data=rownames(GGE)=c("Me","E6","E2","E4","KB","HUl","kat","Dan","EA2","Ts",
"E0","E5","DI","E8","E39","ET1","BO","Ab","Si")
pca =prcomp(GGE[,c(2:11)], center = TRUE,scale. = TRUE)
print(pca)
to get eigen value
eig.val = get_eigenvalue(pca)
eig.val
#to get scree plot
fviz_eig(pca, addlabels = TRUE, ylim = c(0, 50))
PCA results for variables
var=get_pca_var(pca)
to see the most contributing variables for each dimension
corrplot(var$cos2, is.corr=FALSE)
#to see the most contributing variables for both dimension
fviz_cos2(pca, choice = "var", axes = 1:2)
to draw a bar plot of variable contributions
Contributions of variables to PC1
a=fviz_contrib(pca, choice = "var", axes = 1)# top= 5 to limit to five var.
Contributions of variables to PC2
b=fviz_contrib(pca, choice = "var", axes = 2)
grid.arrange(a,b, ncol=2, top='Contribution of the variables to the first two PCs')
Total contribution on PC1 and PC2
fviz_contrib(pca, choice = "ind", axes = 1:2)
#Graph of variables
fviz_pca_var(pca,
col.var = "cos2",
gradient.cols = c("red", "blue", "green"),
repel = TRUE)
#Biplot of individuals and variables
fviz_pca_biplot(pca, repel = TRUE,
col.var = "blue",
col.ind = "red")
#########################################################################
#Plotting PCA
ggbiplot(pca)
#This will name each point with the name of the genotypes
ggbiplot(pca,labels=rownames(GGE))
plot using PC1 and PC2
ggbiplot(pca,ellipse=TRUE,choices=c(1,2),labels=rownames(GGE), groups=GGE$ENV)
scale the samples
ggbiplot(pca,ellipse=TRUE,obs.scale = 2, var.scale = 4.5,
labels=rownames(GGE), groups=GGE$ENV)
#remove the arrows altogether
ggbiplot(pca,ellipse=TRUE,obs.scale = 1, var.scale = 1,var.axes=FALSE,
labels=rownames(GGE), groups=GGE$ENV)
final biplot by Customize ggbiplot
aa=ggbiplot(pca,ellipse=TRUE,obs.scale = 1, var.scale = 1, labels=rownames(GGE), groups=GGE$ENV) +
scale_colour_manual(name="Location", values= c("blue", "red", "green","pink"))+
ggtitle("PCA of wakjira")+
theme_minimal()+
theme(legend.position = "bottom")
aa
ggsave(filename = "Waq.png", plot = aa,width = 22, height = 15, dpi = 2500, units = "cm")
This is by far the best tutorial on doing PCA using R statistics. Thank you so much
Thank you.
The best tutorial on how to compute PCA using R. Thank you!
this is by far the best explanatory video on PCA. strangely I can't install corrplot and ggbilot packages
Use this codes
library(devtools)
install_github("vqv/ggbiplot")
########################
devtools::install_github('taiyun/corrplot', build_vignettes = TRUE)
Thanks
same here, but it still can't install ggbiplot
@@wakjiratesfahun3682
thank you so much. This is the best tutorial on running PCA using Rstudio. more grace
The best explanation that I have found; thank you very much.
Glad it was helpful!
Thank you. This is a very good explanation of PCA. Very useful, I am using what I learned from it in my research work.
Thank you .
Thank you so much very helpful Waki, Please keep up the good work!.
Thanks burte.
Was very helpful. Thank you Sir.
Thank you for you positive feedback
Excellent presentation
Thank you so much.
Thank you for explanations and sharing the helpful and nice work
Thank you brother.
Best tutor ever!
Thank you.
Thanks for uploading this video
I thank you for your suggestion.
well explained
well illustrated
Thank you Mohammed for you constructive feedback.
@@wakjiratesfahun3682 you'r wlcm
Wonderful video, Thank you very much
Thanks.
This is really helpful. Thank you. However, do you have transcribed commentaries on what you were saying whilst you were running the codes? it will be helpful since I did not catch some of the things you said.
Sorry I didn't transcribe it.
Wonderful video...thank you so much for this 😊
Thank you for your comment.
Thank you!!
Thanks
Wonderful explanation...Thank you so much
Thanks for a nice explanation
Thank you.
Well explained
Thank you brother for your constructive comments.
Thanks Prof for this wonderful lecture. Am having problems installing ggbiplot, any hint you can help me with? thanks
Run this code
library(devtools)
install_github("vqv/ggbiplot")
library(devtools)
Error: package ‘usethis’ 2.1.5 was found, but >= 2.1.6 is required by ‘devtools’
In addition: Warning message:
package ‘devtools’ was built under R version 4.1.3
> install_github("vqv/ggbiplot")
Error in install_github("vqv/ggbiplot") :
could not find function "install_github"= this is the errors I have been having since before I contacted you
@@wakjiratesfahun3682
Thank you Sir 🙏❤
Thanks bro.
Perfect Video thanks
Thanks.
really I like it. Thank you!
Thank you very much.
Thank you so much!!! Thank you for sharing knowledge!
Thank you.
The Greatest one !!!!
Thank you.
it is good english
thank you
Thanks!
Thank you!
Awesome tutorial
Dear, i have tried to search the normality checking youtube that was done by you but I couldn't find it, please would you help me?
I did a tutorial on normality test. Please check my channel.
Thank you🙏 for your important tutorial. but how do I arrange my data from a simple lattice design? can I use the mean for the parameters??
Yeah you have to use the mean value.
Too impressive, moreover is there this tube in Amharic language?
Initially planned to give a tutorial in Amharic but due to bunch request , I changed the medium to English.
Thanks sir for this video
Sir I want to analyse the effect of physicochemical parameters of waterbody on the distribution of single species of fish.can you please suggest me the appropriate stastical tool .so that I can get results
What is your objective ?
Realy nice,
Thanks
Hi Prof please how to fix this error when running this script
fviz_eig(pca, addlabels = TRUE, ylim = c(0, 50))
Error in loadNamespace(j = 3.4.0 is required. I tried to install Cli but still not working. thanks
Uninstall Cli and install the latest package.
Good luck !
OK thanks prof
Thank you
Okay.
I came across this code in PCA analysis.
Error in names(df.v)
Can you share me the code
If the number of row is large, for example my data has 140 row so what I shall do?
Thank you for the video! I have a question, for the ggbiplot, how can I select just some variables/axes to represent ?
I didn't get you. Can you elaborate please.
superlike
Shukurya Subhankar!
how to label each PC in final chart with traits
Give me the title and I will provide the code for you.
Thanks for video.
I have a question Sir
I can't run the ggbiplot command. I'm trying to download it still doesn't work. How we can solve this problem?
Can you help me
Thanks for the question.
I released a video yesterday . Please check it. You will get answer.
Thanks you Sir
Best
Can we do PCA in a three-factor study ?
@@cengizturkay9230 Pca deals with numbers. Why you bother about factors ?
thank you for the explanation, but why i couldn't find this command
(library("ggplot2")
library("gridExtra")
library(ggbiplot)
library("corrplot")
library(factoextra)
it always said error
Can you share the error.
Sir the ggbiplot is not functin in New Update R ???
what happened?
@@wakjiratesfahun3682 Have done sir, ggbiplot I get from git hub recently.. and I want ask you about how we can add the colour of contribution line in pca ggbiplot version, like graph Fvis or add some ellipse lshape in graph Fvis.. Thanks
Hi thank you for your video. However, I tried to use your codes with my data but I cannot get the Eigenvalue. I hit this error 'Error in get_eigenvalue(pca) : could not find function "get_eigenvalue".
You forget to run factoextra package .
@@wakjiratesfahun3682 Thank you so much for your assistance. I ran, but I tried to install the "ggbiplot" package in vain; I could not. Any other way to install it?
@@nduwayezugilbert7912 I made a tutorial on some packages that found in other repositories.Please use this code to install ggbiplot.
library(devtools) install_github("vqv/ggbiplot")
@@wakjiratesfahun3682 Thank you so much
@@nduwayezugilbert7912 it's okay.
can I get the data file for practice
Does R software free access?
Well explained
Thank you Beza.
Sir i changed the rownames but in pca plot it shows same (1,2 ,3....),can you slove this problem pls
your code please