PCA Maker Shiny App

[This article was first published on R in the Lab, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:

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 🤓


https://twitter.com/JuanPa2601

The text on this tutorial is under Creative Commons Attribution 4.0 International License.

CC BY 4.0

PCA Maker is under GNU General Public License v3.0

To leave a comment for the author, please follow the link and comment on their blog: R in the Lab.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)