casperyc
2012-Mar-23 21:40 UTC
[R] show and produce PDF file with pdf() and dev.off( ) in function
Hi all, I know how to use pdf() and dev.off() to produce and save a graph. However, when I put them in a function say myplot(x=1:20){ pdf("xplot.pdf") plot(x) dev.off() } the function work. But is there a way show the graph in R as well as saving it to the workspace? Thanks. casper ----- ################################################### PhD candidate in Statistics School of Mathematics, Statistics and Actuarial Science, University of Kent ################################################### -- View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500213.html Sent from the R help mailing list archive at Nabble.com.
chuck.01
2012-Mar-24 02:03 UTC
[R] show and produce PDF file with pdf() and dev.off( ) in function
1) thats not a function (i'm sure just a mistake) 2) Just add another plot line myplot <- function(x){ plot(x) pdf("xplot.pdf") plot(x) dev.off() } myplot(1:20) casperyc wrote> > Hi all, > > I know how to use pdf() and dev.off() to produce and save a graph. > > However, when I put them in a function say > > myplot(x=1:20){ > pdf("xplot.pdf") > plot(x) > dev.off() > } > > the function work. But is there a way show the graph in R as well as > saving it to the workspace? > > Thanks. > > casper >-- View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500595.html Sent from the R help mailing list archive at Nabble.com.
Igor Sosa Mayor
2012-Mar-24 12:11 UTC
[R] show and produce PDF file with pdf() and dev.off( ) in function
apart from the other answers, be aware that you have to 'print' the graph with pl<-plot(x) print(pl) in case you're using lattice or ggplot2 plots. On Fri, Mar 23, 2012 at 02:40:04PM -0700, casperyc wrote:> Hi all, > > I know how to use pdf() and dev.off() to produce and save a graph. > > However, when I put them in a function say > > myplot(x=1:20){ > pdf("xplot.pdf") > plot(x) > dev.off() > } > > the function work. But is there a way show the graph in R as well as saving > it to the workspace? > > Thanks. > > casper > > ----- > ################################################### > PhD candidate in Statistics > School of Mathematics, Statistics and Actuarial Science, University of Kent > ################################################### > > -- > View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500213.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- :: Igor Sosa Mayor :: joseleopoldo1792 at gmail.com :: :: GnuPG: 0x1C1E2890 :: http://www.gnupg.org/ :: :: jabberid: rogorido :: :: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120324/140bdcdf/attachment.bin>