This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ggplot and DESeq2 PCA plot

Hi all, I am trying to convert my PCA plot which is created with DESeq2 to ggplot object but somehow I couldnt manage to do it.

pcaPlot <- plotPCA(dds, intgroup = "types", ntop = nrow(dds), returnData = TRUE) 
annotated_pcaPlot <- ggplot(geom_text(pcaPlot,aes(label=name,group=group)))+geom_text(size = 3,position = position_nudge(y = -0.03))+
  theme_test(base_family = "Arial") +geom_point(aes(color=group))+scale_color_manual(values=c('Purple3','Orangered'))

Error in validate_mapping(): ! mapping must be created by aes() Run rlang::last_error() to see where the error occurred. rlang::last_error() <error/rlang_error> Error in validate_mapping(): ! mapping must be created by aes() --- Backtrace:

  1. ggplot2::ggplot(geom_text(pcaPlot, aes(label = name, group = group)))
  2. ggplot2::geom_text(pcaPlot, aes(label = name, group = group))
  3. ggplot2::layer(...)
  4. ggplot2:::validate_mapping(mapping) Run rlang::last_trace() to see the full context.

I am getting this error when I run like above. Do you have any recommendations ?

ggplot pca rna-seq deseq2

I believe there is an inadequate geom_text after introducing ggplot() that should not be here

1 answer

Your issue is with the following:

ggplot(geom_text(pcaPlot,aes(label=name,group=group)))

You should instead do:

ggplot(pcaPlot, aes(label = name, group = group))+
    geom_text()+

Log in to answer this question.