Problem with exporting graph from plotPCA() in a DESeq2 function
1
0
Entering edit mode
Guest User ★ 13k
@guest-user-4897
Last seen 10.3 years ago
Hi! I am currently programming a function for easy use of DESeq2. I would like to export my graphs with the pdf() command. It works fine for the dispersion graph and other volcano plots that I programmed, but I encountered some problems with the plotPCA() function. First I have to execute it at the very end of the function to see the graph, and the if I use pdf()... dev.off / graphics.off(), the pdf file contains all graphs but the PCA graph. I tried it line by line in the console, it works fine. I usually work with RStudio, but under R it didn't work either. Any ideas? Thanks for your help, Fabrice. -- output of sessionInfo(): > sessionInfo("DESeq2") R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: character(0) other attached packages: [1] DESeq2_1.2.10 loaded via a namespace (and not attached): [1] annotate_1.40.0 AnnotationDbi_1.24.0 base_3.0.2 [4] Biobase_2.22.0 BiocGenerics_0.8.0 BiocInstaller_1.12.0 [7] datasets_3.0.2 DBI_0.2-7 genefilter_1.44.0 [10] GenomicRanges_1.14.4 graphics_3.0.2 grDevices_3.0.2 [13] grid_3.0.2 IRanges_1.20.6 lattice_0.20-24 [16] locfit_1.5-9.1 methods_3.0.2 parallel_3.0.2 [19] RColorBrewer_1.0-5 Rcpp_0.11.0 RcppArmadillo_0.4.000.2 [22] rJava_0.9-6 RSQLite_0.11.4 splines_3.0.2 [25] stats_3.0.2 stats4_3.0.2 survival_2.37-7 [28] tools_3.0.2 utils_3.0.2 xlsx_0.5.5 [31] xlsxjars_0.5.0 XML_3.98-1.1 xtable_1.7-1 [34] XVector_0.2.0 > packageDescription('DESeq2')$Maintainer [1] "Michael Love <michaelisaiahlove at="" gmail.com="">" -- Sent via the guest posting facility at bioconductor.org.
graph DESeq2 graph DESeq2 • 5.0k views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 6 hours ago
United States
hi Fabrice, plotPCA() returns a call to xyplot() which is a function of the lattice package. I didn't try this yet, but typically the solution with lattice plots is a print call: plt <- plotPCA(...) print(plt) see http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/print.trelli s.html Mike On Mon, Feb 10, 2014 at 8:32 AM, Fabrice Chatonnet [guest] < guest@bioconductor.org> wrote: > > Hi! > > I am currently programming a function for easy use of DESeq2. I would like > to export my graphs with the pdf() command. It works fine for the > dispersion graph and other volcano plots that I programmed, but I > encountered some problems with the plotPCA() function. First I have to > execute it at the very end of the function to see the graph, and the if I > use pdf()... dev.off / graphics.off(), the pdf file contains all graphs but > the PCA graph. > I tried it line by line in the console, it works fine. > I usually work with RStudio, but under R it didn't work either. Any ideas? > > Thanks for your help, > > Fabrice. > > -- output of sessionInfo(): > > > sessionInfo("DESeq2") > R version 3.0.2 (2013-09-25) > Platform: x86_64-w64-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 > [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C > [5] LC_TIME=French_France.1252 > > attached base packages: > character(0) > > other attached packages: > [1] DESeq2_1.2.10 > > loaded via a namespace (and not attached): > [1] annotate_1.40.0 AnnotationDbi_1.24.0 base_3.0.2 > [4] Biobase_2.22.0 BiocGenerics_0.8.0 BiocInstaller_1.12.0 > [7] datasets_3.0.2 DBI_0.2-7 genefilter_1.44.0 > [10] GenomicRanges_1.14.4 graphics_3.0.2 grDevices_3.0.2 > [13] grid_3.0.2 IRanges_1.20.6 lattice_0.20-24 > [16] locfit_1.5-9.1 methods_3.0.2 parallel_3.0.2 > [19] RColorBrewer_1.0-5 Rcpp_0.11.0 > RcppArmadillo_0.4.000.2 > [22] rJava_0.9-6 RSQLite_0.11.4 splines_3.0.2 > [25] stats_3.0.2 stats4_3.0.2 survival_2.37-7 > [28] tools_3.0.2 utils_3.0.2 xlsx_0.5.5 > [31] xlsxjars_0.5.0 XML_3.98-1.1 xtable_1.7-1 > [34] XVector_0.2.0 > > > packageDescription('DESeq2')$Maintainer > [1] "Michael Love <michaelisaiahlove@gmail.com>" > > -- > Sent via the guest posting facility at bioconductor.org. > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
Dear Mike, Regarding the plotPCA() of DESeq2, is there a way to add the sample names on the plot? If not do you plan to modify the function, in the next DESeq2 release, in order to see the sample names in the plot? Thank you Ugo > From: Michael Love <michaelisaiahlove at="" gmail.com=""> > Date: Mon, 10 Feb 2014 08:42:12 -0500 > To: "Fabrice Chatonnet [guest]" <guest at="" bioconductor.org=""> > Cc: <fabrice.chatonnet at="" ens-lyon.org="">, "bioconductor at r-project.org" > <bioconductor at="" r-project.org=""> > Subject: Re: [BioC] Problem with exporting graph from plotPCA() in a DESeq2 > function > > hi Fabrice, > > plotPCA() returns a call to xyplot() which is a function of the lattice > package. I didn't try this yet, but typically the solution with lattice > plots is a print call: > > plt <- plotPCA(...) > print(plt) > > see > http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/print.trel lis.html > > Mike > > > On Mon, Feb 10, 2014 at 8:32 AM, Fabrice Chatonnet [guest] < > guest at bioconductor.org> wrote: > >> >> Hi! >> >> I am currently programming a function for easy use of DESeq2. I would like >> to export my graphs with the pdf() command. It works fine for the >> dispersion graph and other volcano plots that I programmed, but I >> encountered some problems with the plotPCA() function. First I have to >> execute it at the very end of the function to see the graph, and the if I >> use pdf()... dev.off / graphics.off(), the pdf file contains all graphs but >> the PCA graph. >> I tried it line by line in the console, it works fine. >> I usually work with RStudio, but under R it didn't work either. Any ideas? >> >> Thanks for your help, >> >> Fabrice. >> >> -- output of sessionInfo(): >> >>> sessionInfo("DESeq2") >> R version 3.0.2 (2013-09-25) >> Platform: x86_64-w64-mingw32/x64 (64-bit) >> >> locale: >> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 >> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C >> [5] LC_TIME=French_France.1252 >> >> attached base packages: >> character(0) >> >> other attached packages: >> [1] DESeq2_1.2.10 >> >> loaded via a namespace (and not attached): >> [1] annotate_1.40.0 AnnotationDbi_1.24.0 base_3.0.2 >> [4] Biobase_2.22.0 BiocGenerics_0.8.0 BiocInstaller_1.12.0 >> [7] datasets_3.0.2 DBI_0.2-7 genefilter_1.44.0 >> [10] GenomicRanges_1.14.4 graphics_3.0.2 grDevices_3.0.2 >> [13] grid_3.0.2 IRanges_1.20.6 lattice_0.20-24 >> [16] locfit_1.5-9.1 methods_3.0.2 parallel_3.0.2 >> [19] RColorBrewer_1.0-5 Rcpp_0.11.0 >> RcppArmadillo_0.4.000.2 >> [22] rJava_0.9-6 RSQLite_0.11.4 splines_3.0.2 >> [25] stats_3.0.2 stats4_3.0.2 survival_2.37-7 >> [28] tools_3.0.2 utils_3.0.2 xlsx_0.5.5 >> [31] xlsxjars_0.5.0 XML_3.98-1.1 xtable_1.7-1 >> [34] XVector_0.2.0 >> >>> packageDescription('DESeq2')$Maintainer >> [1] "Michael Love <michaelisaiahlove at="" gmail.com="">" >> >> -- >> Sent via the guest posting facility at bioconductor.org. >> > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
Ciao Ugo the function plotPCA is trivial so it is not difficult to replace it with one adapted to your tastes. (Just type ?plotPCA? without the ?()? in the R command line.) Furthermore, as Mike mentioned, plotPCA returns the trellis object, and you can update it - see e.g. http://stackoverflow.com/questions/6606902/add-labels-on-lattice- xyplot A working example is: library("DESeq2") library("lattice") example(plotPCA) myplot = plotPCA(vsd) names = colData(vsd)$sample myplot = update(myplot, panel = function(x, y, ...) { panel.xyplot(x, y, ...); ltext(x=x, y=y, labels=names, pos=1, offset=1, cex=0.8) }) There are various packages on CRAN to provide automated moving around of the labels to avoid overplotting, and there are also options for producing the plot as SVG/HTML5 with interactive tooltips ?. But then these things are general R and not specific to DESeq2, of course. best wishes Wolfgang On 10 Feb 2014, at 14:55, Ugo Borello <ugo.borello at="" inserm.fr=""> wrote: > Dear Mike, > Regarding the plotPCA() of DESeq2, is there a way to add the sample names on > the plot? > If not do you plan to modify the function, in the next DESeq2 release, in > order to see the sample names in the plot? > > Thank you > > Ugo > > >> From: Michael Love <michaelisaiahlove at="" gmail.com=""> >> Date: Mon, 10 Feb 2014 08:42:12 -0500 >> To: "Fabrice Chatonnet [guest]" <guest at="" bioconductor.org=""> >> Cc: <fabrice.chatonnet at="" ens-lyon.org="">, "bioconductor at r-project.org" >> <bioconductor at="" r-project.org=""> >> Subject: Re: [BioC] Problem with exporting graph from plotPCA() in a DESeq2 >> function >> >> hi Fabrice, >> >> plotPCA() returns a call to xyplot() which is a function of the lattice >> package. I didn't try this yet, but typically the solution with lattice >> plots is a print call: >> >> plt <- plotPCA(...) >> print(plt) >> >> see >> http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/print.tre llis.html >> >> Mike >> >> >> On Mon, Feb 10, 2014 at 8:32 AM, Fabrice Chatonnet [guest] < >> guest at bioconductor.org> wrote: >> >>> >>> Hi! >>> >>> I am currently programming a function for easy use of DESeq2. I would like >>> to export my graphs with the pdf() command. It works fine for the >>> dispersion graph and other volcano plots that I programmed, but I >>> encountered some problems with the plotPCA() function. First I have to >>> execute it at the very end of the function to see the graph, and the if I >>> use pdf()... dev.off / graphics.off(), the pdf file contains all graphs but >>> the PCA graph. >>> I tried it line by line in the console, it works fine. >>> I usually work with RStudio, but under R it didn't work either. Any ideas? >>> >>> Thanks for your help, >>> >>> Fabrice. >>> >>> -- output of sessionInfo(): >>> >>>> sessionInfo("DESeq2") >>> R version 3.0.2 (2013-09-25) >>> Platform: x86_64-w64-mingw32/x64 (64-bit) >>> >>> locale: >>> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 >>> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C >>> [5] LC_TIME=French_France.1252 >>> >>> attached base packages: >>> character(0) >>> >>> other attached packages: >>> [1] DESeq2_1.2.10 >>> >>> loaded via a namespace (and not attached): >>> [1] annotate_1.40.0 AnnotationDbi_1.24.0 base_3.0.2 >>> [4] Biobase_2.22.0 BiocGenerics_0.8.0 BiocInstaller_1.12.0 >>> [7] datasets_3.0.2 DBI_0.2-7 genefilter_1.44.0 >>> [10] GenomicRanges_1.14.4 graphics_3.0.2 grDevices_3.0.2 >>> [13] grid_3.0.2 IRanges_1.20.6 lattice_0.20-24 >>> [16] locfit_1.5-9.1 methods_3.0.2 parallel_3.0.2 >>> [19] RColorBrewer_1.0-5 Rcpp_0.11.0 >>> RcppArmadillo_0.4.000.2 >>> [22] rJava_0.9-6 RSQLite_0.11.4 splines_3.0.2 >>> [25] stats_3.0.2 stats4_3.0.2 survival_2.37-7 >>> [28] tools_3.0.2 utils_3.0.2 xlsx_0.5.5 >>> [31] xlsxjars_0.5.0 XML_3.98-1.1 xtable_1.7-1 >>> [34] XVector_0.2.0 >>> >>>> packageDescription('DESeq2')$Maintainer >>> [1] "Michael Love <michaelisaiahlove at="" gmail.com="">" >>> >>> -- >>> Sent via the guest posting facility at bioconductor.org. >>> >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
Thank you very much. It will experiment with the code right away. Ugo > From: Wolfgang Huber <whuber at="" embl.de=""> > Date: Mon, 10 Feb 2014 16:27:24 +0100 > To: Ugo Borello <ugo.borello at="" inserm.fr=""> > Cc: Michael Love <michaelisaiahlove at="" gmail.com="">, "Fabrice Chatonnet [guest]" > <guest at="" bioconductor.org="">, <fabrice.chatonnet at="" ens-lyon.org="">, > "bioconductor at r-project.org" <bioconductor at="" r-project.org=""> > Subject: Re: [BioC] Problem with exporting graph from plotPCA() in a DESeq2 > function > > Ciao Ugo > > the function plotPCA is trivial so it is not difficult to replace it with one > adapted to your tastes. (Just type ?plotPCA? without the ?()? in the R command > line.) Furthermore, as Mike mentioned, plotPCA returns the trellis object, and > you can update it - see e.g. > http://stackoverflow.com/questions/6606902/add-labels-on-lattice- xyplot A > working example is: > > library("DESeq2") > library("lattice") > example(plotPCA) > > myplot = plotPCA(vsd) > names = colData(vsd)$sample > > myplot = update(myplot, panel = function(x, y, ...) { > panel.xyplot(x, y, ...); > ltext(x=x, y=y, labels=names, pos=1, offset=1, cex=0.8) > }) > > There are various packages on CRAN to provide automated moving around of the > labels to avoid overplotting, and there are also options for producing the > plot as SVG/HTML5 with interactive tooltips ?. But then these things are > general R and not specific to DESeq2, of course. > > best wishes > Wolfgang > > > On 10 Feb 2014, at 14:55, Ugo Borello <ugo.borello at="" inserm.fr=""> wrote: > >> Dear Mike, >> Regarding the plotPCA() of DESeq2, is there a way to add the sample names on >> the plot? >> If not do you plan to modify the function, in the next DESeq2 release, in >> order to see the sample names in the plot? >> >> Thank you >> >> Ugo >> >> >>> From: Michael Love <michaelisaiahlove at="" gmail.com=""> >>> Date: Mon, 10 Feb 2014 08:42:12 -0500 >>> To: "Fabrice Chatonnet [guest]" <guest at="" bioconductor.org=""> >>> Cc: <fabrice.chatonnet at="" ens-lyon.org="">, "bioconductor at r-project.org" >>> <bioconductor at="" r-project.org=""> >>> Subject: Re: [BioC] Problem with exporting graph from plotPCA() in a DESeq2 >>> function >>> >>> hi Fabrice, >>> >>> plotPCA() returns a call to xyplot() which is a function of the lattice >>> package. I didn't try this yet, but typically the solution with lattice >>> plots is a print call: >>> >>> plt <- plotPCA(...) >>> print(plt) >>> >>> see >>> http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/print.tr ellis.html >>> >>> Mike >>> >>> >>> On Mon, Feb 10, 2014 at 8:32 AM, Fabrice Chatonnet [guest] < >>> guest at bioconductor.org> wrote: >>> >>>> >>>> Hi! >>>> >>>> I am currently programming a function for easy use of DESeq2. I would like >>>> to export my graphs with the pdf() command. It works fine for the >>>> dispersion graph and other volcano plots that I programmed, but I >>>> encountered some problems with the plotPCA() function. First I have to >>>> execute it at the very end of the function to see the graph, and the if I >>>> use pdf()... dev.off / graphics.off(), the pdf file contains all graphs but >>>> the PCA graph. >>>> I tried it line by line in the console, it works fine. >>>> I usually work with RStudio, but under R it didn't work either. Any ideas? >>>> >>>> Thanks for your help, >>>> >>>> Fabrice. >>>> >>>> -- output of sessionInfo(): >>>> >>>>> sessionInfo("DESeq2") >>>> R version 3.0.2 (2013-09-25) >>>> Platform: x86_64-w64-mingw32/x64 (64-bit) >>>> >>>> locale: >>>> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 >>>> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C >>>> [5] LC_TIME=French_France.1252 >>>> >>>> attached base packages: >>>> character(0) >>>> >>>> other attached packages: >>>> [1] DESeq2_1.2.10 >>>> >>>> loaded via a namespace (and not attached): >>>> [1] annotate_1.40.0 AnnotationDbi_1.24.0 base_3.0.2 >>>> [4] Biobase_2.22.0 BiocGenerics_0.8.0 BiocInstaller_1.12.0 >>>> [7] datasets_3.0.2 DBI_0.2-7 genefilter_1.44.0 >>>> [10] GenomicRanges_1.14.4 graphics_3.0.2 grDevices_3.0.2 >>>> [13] grid_3.0.2 IRanges_1.20.6 lattice_0.20-24 >>>> [16] locfit_1.5-9.1 methods_3.0.2 parallel_3.0.2 >>>> [19] RColorBrewer_1.0-5 Rcpp_0.11.0 >>>> RcppArmadillo_0.4.000.2 >>>> [22] rJava_0.9-6 RSQLite_0.11.4 splines_3.0.2 >>>> [25] stats_3.0.2 stats4_3.0.2 survival_2.37-7 >>>> [28] tools_3.0.2 utils_3.0.2 xlsx_0.5.5 >>>> [31] xlsxjars_0.5.0 XML_3.98-1.1 xtable_1.7-1 >>>> [34] XVector_0.2.0 >>>> >>>>> packageDescription('DESeq2')$Maintainer >>>> [1] "Michael Love <michaelisaiahlove at="" gmail.com="">" >>>> >>>> -- >>>> Sent via the guest posting facility at bioconductor.org. >>>> >>> >>> [[alternative HTML version deleted]] >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >>> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode

hi Ugo,

Here is some code for DESeq2 (>= 1.7.5) to put labels on top of the points in the PCA plot. For version 1.6, use names instead of name.

r = rlog(dds)
d = plotPCA(r, returnData=TRUE)
library(ggplot2)
ggplot(d, aes(x=PC1,y=PC2,col=condition,label=name)) + geom_point() + geom_text()
ADD REPLY

Login before adding your answer.

Traffic: 982 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.6