When i run the below code of lines in R version 4.0.3 throws the below error message: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘plotPCA’ for signature ‘"prcomp"’
Code should be placed in three backticks as shown below
library(SMLoutliers)
library(plotly)
library(DESeq2)
library(ggplot2)
library(datasets)
library(BiocGenerics)
library(scatterplot3d)
library(plyr)
library(dplyr)
data(stiff)
#calculating Maha distance for Data
mahaDistance<-mahalanobis(stiff,colMeans(stiff),var(stiff))
stiff$MahaDistance<- mahaDistance
stiff1<-arrange(stiff,desc(MahaDistance))
#identifying outliers (first 5 outliers)
stiff1$outliers<- c(rep("outlier",5),rep("not-outlier",nrow(stiff1)-5))
stiff1$outliers
#plotting outliers using PCA
pca_estudio<-prcomp(stiff1[,1:4], center = TRUE,scale. = FALSE)
ggplotly(plotPCA(pca_estudio,vectorVariables = c("x1","x2"),groups =stiff1$outliers))
As already mentioned, the input is wrong. You must use a DESeqTransform object, so the output of either vst or rlog. The PCA is performed internally based on the (by default 500) most variable genes of that object. Please read the DESeq2 manual and ?plotPCA help page where this is clearly explained.