- Create an interactive web service using ShinyApp to perform Principal Component Analysis (PCA) and Correspondence Analysis (CA).
- Integrate Example Script: Integrating the folllowing script into a Shiny application. While
ggbiplot
is recommended for creating biplots in PCA, feel free to explore and use other packages suitable for PCA and CA if necessary.
data(iris)
# log transform
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]
# apply PCA - scale. = TRUE is highly advisable, but the default is FALSE.
ir.pca <- prcomp(log.ir,center = TRUE, scale. = TRUE)
library(ggbiplot)
g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', legend.position = 'top')
print(g)
- Installation of ggbiplot: The
ggbiplot
package is not available on CRAN and must be installed from GitHub using the following command in RStudio:
devtools::install_github("vqv/ggbiplot")
- Connect Shinyapps.io with RStudio:
- Preview Application: After completing your Shiny application, preview it in the RStudio console using the appropriate command to initiate your app locally.
library(shiny)
shinyApp(ui = ui, server = server)
- Publish:
- On the preview screen, locate the
Publish
button in the upper right corner. Click it to deploy your application to ShinyApps.io.
- On the preview screen, locate the
- R Version: Ensure you are using R version 4 for this assignment.