We will illustrate some widgets for 3D scatterplots to enhance output of PCA in PLNmodels. The packages required for the analysis are PLNmodels plus some others for data manipulation and representation:
library(PLNmodels)
library(tidyverse)
library(ggplot2)
Here are a collection of packages implementing various JS widgets:
library(DT)
library(scatterD3)
library(plotly)
library(edgebundleR)
library(threejs)
library(networkD3)
The oaks amplicon data set at play gives the abundance of 114 taxa (66 bacterial OTU, 48 fungal OTUs) in 116 samples. For each sample, 11 additional covariates are known
data(oaks)
datatable(oaks$Abundance[, 1:5] )
We only fit two PCA models, which we know are in the right range for ICL
PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = 27:28) my_PCAs <-
We explore various scatterplot solutions to represent the individual factor map of the PLN PCA.
my_PCAs$getBestModel()$scores[, 1:3] %>%
coord <- as.data.frame() %>%
setNames(c("PC1", "PC2", "PC3")) %>%
add_column(tree = oaks$tree, names = rownames(oaks$Abundance))
scatterD3(data = coord, x = PC1, y = PC2, lab = names,
col_var = tree, symbol_var = tree,
xlab = "PC1", ylab = "PC2", col_lab = "tree",
symbol_lab = "tree", lasso = TRUE)
plot_ly(
fig <-x = ~PC1, y = ~PC2, z = ~PC3, color = ~tree, size = .35,
coord, text = ~paste('status:', tree), type = "scatter3d") %>%
layout(title = "Individual Factor Map of the Oaks powdery Mildew data set",
scene = list(xaxis = list(title = 'PC1'),
yaxis = list(title = 'PC2'),
zaxis = list(title = 'PC3'))
) fig
rainbow(3)[as.numeric(oaks$tree)]
group <-%>% select(1:3) %>% as.matrix() %>%
coord scatterplot3js(col = group, size = 0.25, pch = ".", grid = FALSE, bg = "black")