use object of S4 class SeqExpressionSet to plot PCA with ggplot2

219 Views Asked by At

I have made an object of S4 class SeqExpressionSet with EDASeq which I can then analyse with plotPCA.

However the plotPCA function lacks the ability to fully adjust aesthetics. I was therefore wondering whether it is possible to change the dataset somehow so I can use it with e.g. ggplot2 or a different package that enables more adjustments.

1

There are 1 best solutions below

0
On

I'm not familiar with EDAseq, but my best guess is that you'd have to do a PCA manually and plot those results. Assuming your object is called my_object and the source code posted here, you can reconstruct the process as follows:

dat <- normCounts(my_object)
dat <- apply(dat, 1, function(y) scale(y, center = TRUE, scale = FALSE))

s <- svd(dat)

df <- data.frame(
  PC1 = s$u[, 1], PC2 = s$u[, 2]
)

ggplot(df, aes(PC1, PC2)) +
  geom_point()

Note that I haven't tested this code as I don't have example data and was too lazy to install EDAseq.