Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘plotPCA’ for signature ‘"prcomp"’
0
Entering edit mode
@Sowbhagyalakshmi-24747
Last seen 22 days ago

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))
plotGrouper DESeq2 plot • 63 views
ADD COMMENTlink
0
Entering edit mode

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.

ADD REPLYlink
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 hours ago
United States

This error is simply telling you that a prcomp object isn't a valid input for plotPCA. You can see what valid inputs are, using showMethods

> showMethods(plotPCA)
Function: plotPCA (package BiocGenerics)
object="DESeqTransform"

and further you can use the help page ?plotPCA, which says (after you choose the DESeq2 help page)

Description:

     This plot helps to check for batch effects and the like.

Usage:

     ## S4 method for signature 'DESeqTransform'
     plotPCA(object, intgroup = "condition", ntop = 500, returnData = FALSE)

Arguments:

  object: a 'DESeqTransform' object, with data in 'assay(x)', produced
          for example by either 'rlog' or
          'varianceStabilizingTransformation'.

You can plot the results from running prcomp directly, doing something like

plot(pca_estudio$x[,1:2])

And modifying to use different plotting symbols, etc

Login before adding your answer.

Similar Posts
Loading Similar Posts
Traffic: 211 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.4