Re: [R] Producing graphs and console output in postscript format

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Tue, 19 Feb 2008 09:20:19 -0700

Have you looked at Sweave? It allows you to put all your commands into a template file along with details on where you want graphs and any other markup. You can also include other text (notes, explanations, etc) that will show up in the output, but not be processed by R. The original version of Sweave uses LaTeX and naturally leads to a postscript document. There are also variations on Sweave available to work with HTML or OpenOffice documents.

Sweave does require you to plan ahead what commands you want to run, then creates the output. If you are more interested in capturing your output as you do an analysis that you do not have the commands preplanned, then the closest I know of is the R2HTML package wich captures the output and graphs that you specify to an HTML document (you could then print that to a tool that creates postscript files). You could look at the code for R2HTML and see if you could rewrite some parts to redirct to postscript (or LaTeX) instead of HTML. Note that using R2HTML requires you to tell it which plots you created should be included in the output (run the HTMLplot command when the graph is complete), any tool like this needs either human input on which graphs to include and when, or it will tend to have way more graphs than you really want (if you create a graph, realize you wanted a different color so replot it, then add a reference line, do you want all 3 versions of the graph in the final file? Or just the last one?).

You could also just use sink to save commands and output as text, then when you have a graph that you want to include use dev.copy2eps to save the graph and use cat to include information in the text output about the graph file. Then postprocess your sink text with enscript to create a postscript file (with the correct escapes in place from cat commands the .eps files you create will be included). You could also write a function that combined the copying of the graph to an .eps file and including the appropriate escape in the text file.

Another option is to not capture everything as you go along, but then use the history command to get the set of commands that you ran, put those into a sweave input file, edit a bit (I sometimes do this when showing examples, but edit out the calls to help and all the typos I made) then run Sweave and LaTeX to get the final postscript version.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of John Sorkin
> Sent: Saturday, February 16, 2008 12:54 PM
> To: r-help_at_r-project.org
> Subject: [R] Producing graphs and console output in postscript format
>
> R 2.6.1
> Windows XP
>
> I would like to make a postscript document that contains my
> graphs and the output that I get from the R console. So far,
> all I have been able to do is produce my graphs in postscript
> form. I do this in a sub-optimal manner by MANUALLY saving
> each graph in postscript form. I have not been able to save
> the console output in postscript form. Is there some way that
> I can use the sink() function to save console output in
> postscript form? Is there some way to automatically save each
> graph as a postscript file?
> Thanks,
> John
>
> John Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of
> Gerontology Baltimore VA Medical Center 10 North Greene
> Street GRECC (BT/18/GR) Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)

>
> Confidentiality Statement:
> This email message, including any attachments, is for
> th...{{dropped:6}}
>
> ______________________________________________
> 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.
>
______________________________________________ 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.
Received on Tue 19 Feb 2008 - 16:23:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 16:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive