A brief tutorial encompasing the use of PCA Maker, a web application in R made with Shiny.
The purpose of this post is present a brief tutorial about how to install and use PCA Maker. Some concepts about PCA are covered in other posts on this blog, where you can also found useful links about the topic:
- Principal Component Analysis through Singular Value Decomposition
- Principal Component Analysis (PCA) from Scratch
- Principal Component Analysis to Many Responses
What is PCA Maker?
PCA Maker is a Shiny App that allows to make and deploy principal component analysis from data in CSV and TSV formats.
Install and use
If you are a R and RStudio user, you have two options to use PCA maker.
Download from GitHub
Simply download it from GitHub or through GitHub Desktop, click here: PCA Maker. Once in the PCAMaker main folder, double click on the PCA-Maker.Rproj file:
And type in the R console (you need devtools package):
devtools::laod_all(".")
then type:
PCAMaker()
To do the above, you can also run the file app.R in PCAMaker main directory.
As a package
Install the app as a package with the next code:
devtools::install_github("jpch26/PCA-Maker")
then:
library(PCAMaker)
and finally:
PCAMaker()
This will display the app and now you can see and explore all the tabs and options:
Example
Data
Note that there are preload data sets for which pca results will automatically be display. You can check out these data sets as “Wine_data.csv” and “Wine_region.csv”, in the data directory. For the example I will use other data that is also available in the data directory as “Met_quantities_data.csv” and “Met_time.csv”.
Wine data comes from Wine samples analyzed by GC-MS and FT-IR instruments and metabolomic data comes from Time-course metabolic profiling in Arabidopsis thaliana cell cultures after salt stress treatment
Upload your data
To make a PCA you need two data sets, the first one with your response(s) data in the form:
And the second one with a factor or explanatory variable in the form:
Note that the number of rows in both data sets are the same.
Just click on the left panel, which allows you to search and select your data:
Once you have done the above, the right panel will display a descriptive summary for each response:
At the bottom of the same panel you will find a summary for the explanatory variable:
I strongly think that the way that data is upload can be improved to allow for greater versatility, but for now the app show the best solution I found.
Customize PCA analysis
On this tab you can choose if the responses will be centered around their mean and scaled by their standard deviation, which is something highly recommended and are options selected by default:
On the right panel you will see a summary for your principal component analysis:
Scree Plot
On this tab you will be able to customize the number of principal component to plot, select the format, download your scree plot, and also download the percentages of variation for each principal component as a CSV file:
On the right panel a scree plot will be displayed:
Note that the maximum number of principal components to plot is equal to the number of response variables in your data set.
PCA Scores
Here, on the left panel you will be able to select which principal components will be display in scatter plot showing the scores or projections from your original data. Also you can choose the format, download your plot and the scores as a CSV file:
On the right panel, the scores plot will be displayed. The colors corresponds to each level of your explanatory variable, and the percentage of variation of each principal component is indicated in parentheses:
Loadings
Similar to the previous tab, on the left panel you will able to select several options. Naturally, here the available data corresponds to the loadings, or eigenvectors, for each principal component:
In the left panel a scatter plot with the loading values will be display:
Biplot
This graph was sort of difficult to code, but I adapted a nice solution from the post: Plotting pca biplot with ggplot2.
This tab is pretty similar to the previous ones. The left panel allows you to select the principal components to plot and download your graph:
The right panel shows the biplot:
Thank you so much for your time and for visit this site.
Juan Pablo Carreón Hidalgo 🤓
jpch_26@outlook.com
https://twitter.com/JuanPa2601
The text on this tutorial is under Creative Commons Attribution 4.0 International License.
PCA Maker is under GNU General Public License v3.0