From mboxrd@z Thu Jan 1 00:00:00 1970 From: Austin Frank Subject: [org-babel] suggestions for using tikz() graphic device with org-babel-R Date: Wed, 14 Apr 2010 02:07:11 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1285344707==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O1vlO-0007dT-T6 for emacs-orgmode@gnu.org; Wed, 14 Apr 2010 02:07:50 -0400 Received: from [140.186.70.92] (port=37307 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O1vlL-0007cC-8c for emacs-orgmode@gnu.org; Wed, 14 Apr 2010 02:07:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O1vl6-0002Rh-3d for emacs-orgmode@gnu.org; Wed, 14 Apr 2010 02:07:43 -0400 Received: from lo.gmane.org ([80.91.229.12]:44392) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O1vl5-0002Qy-CB for emacs-orgmode@gnu.org; Wed, 14 Apr 2010 02:07:31 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1O1vl0-00028I-CD for emacs-orgmode@gnu.org; Wed, 14 Apr 2010 08:07:26 +0200 Received: from colossus.cvs.rochester.edu ([128.151.80.181]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Apr 2010 08:07:26 +0200 Received: from austin.frank by colossus.cvs.rochester.edu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Apr 2010 08:07:26 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --===============1285344707== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Hi all-- I'm very excited about a relatively new R package, tikzDevice. This takes R graphics and generates LaTeX code inside a tikzpicture environment that reproduces the desired graphic. This allows, among other things, for all text in a figure to use the same fonts as the rest of your document, and for graph annotations to use latex math markup. I have attached an example org file that has embedded R code that generates figures using the tikz() device.[fn:1] The output from a call to tikz() is a .tex file, which is intended to be included in a larger LaTeX file using the \input{} command. How would the org-babel gurus suggest that I automate the process of embedding these TeX-based graphics in an org file? What is the right combination of :file, :exports, and :results arguments to have the generated file automatically included by a LaTeX \input{} command? Thanks for any advice! /au Footnotes: [fn:1] If requested, I can send the generated tex and pdf files as well --=-=-= Content-Disposition: inline; filename=org-tikz.org~ Content-Transfer-Encoding: quoted-printable #+TITLE: Generating PGF graphics from R in org-babel #+AUTHOR: Austin F. Frank #+EMAIL: austin.frank@gmail.com #+DATE: 2009-12-11 Fri #+LANGUAGE: en #+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc #+LATEX_HEADER: \usepackage{tikz}=20 Recently a new =3DR=3D package, =3DpgfSweave=3D, was announced.[fn:1] This package boasts a fascinating capability: generating all R graphics as \{LaTeX} code that will be typeset using the tikz package and included as PGF graphics.[fn:2] This is an appealing option for several reasons: 1. Scaling of size and adjustments of position should be handled seamlessly and without loss of resolution 2. Colors can be specified identically for graphics and any other markup in the $\LaTeX$ document 3. Since they're just more $\LaTeX$ code, graphics can be manually edited in emacs 4. Same fonts will be used for text in figures as are used in the text of the document 5. $\LaTeX$ markup can be used in figure text 6. tikz integrates nicely with Beamer Given this list of features, I decided to see whether I could get similar functionality in org-babel. * R code ** Load =3DtikzDevice=3D First, we need to load the packages required for producing tikz output in =3DR=3D. If all goes well, you should get a message about the paths to the various programs required to generate $\LaTeX$ markup from within =3DR=3D. #+source: load_tikzDevice #+BEGIN_SRC R :results output :exports both :cache ## I want to show the messages that are generated when the package is ## loaded. These are printed to the equivalent of stderr, so I have ## to rewrite the `message' function to produce output that I can ## print back later. tikz.message <- capture.output(withCallingHandlers(library(tikzDevice), message =3D function (m) cat(m$message))) cat(tikz.message, sep=3D"\n") #+END_SRC ** R example #+source: lmer_example #+BEGIN_SRC R :results output :exports both :cache :session ## I use this library all the time library(lme4) ## here's the standard example m <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy) print(m) #+END_SRC ** Graphics creation #+source: tikz_example #+BEGIN_SRC R :results file :exports code :cache :session library(tikzDevice) ranef.m <- ranef(m, postVar =3D TRUE) tikz(file =3D "ranef.tex", width=3D4, height=3D4) print(qqmath(ranef.m)) dev.off() #+END_SRC #+BEGIN_CENTER #+CAPTION: sample graphics \input{ranef} #+END_CENTER * Footnotes [fn:1] http://thread.gmane.org/gmane.comp.lang.r.packages/351 [fn:2] http://sourceforge.net/projects/pgf/ --=-=-= Content-Transfer-Encoding: quoted-printable =2D-=20 Austin Frank http://aufrank.net GPG Public Key (D7398C2F): http://aufrank.net/personal.asc --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (Darwin) iEYEARECAAYFAkvFW48ACgkQlHMl2/XbR4HyKACdHenTx2teibu6JGrxTkuE1o0D YJYAnjAllBcydOEhLCcUQz7TfPHXtF5v =S8M3 -----END PGP SIGNATURE----- --==-=-=-- --===============1285344707== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============1285344707==--