[R] Graphics and LaTeX documents with the same font

Paul Smith phhs80 at gmail.com
Fri Sep 28 19:03:50 CEST 2007


On 9/28/07, Frank E Harrell Jr <f.harrell at vanderbilt.edu> wrote:
> >>>>>> I know how to export graphics as pdf files and then how to include
> >>>>>> them in LaTeX documents. However, I do not know how to do in
> >>>>>> order to
> >>>>>> have the text of the graphics written with the font selected for the
> >>>>>> LaTeX document. Is that possible?
> >>>>> [...]
> >>> If you don't mind an extra step between R and LaTeX, you could use
> >>> Inkscape to modify your graphics:
> >>>     http://www.inkscape.org/
> >>> It is a (very nice!) vector graphics editor which:
> >>> - works with SVGs (as produced with the RSvgDevice package)
> >>> - imports PDFs (really well in the latest development version)
> >>> - is available for free, on most platforms
> >>> and
> >>> - exports PDFs that nicely integrate in LaTeX documents
> >>> - exports PSTricks graphics
> >>> Then two roads are opened for you:
> >>> 1- either get a TTF version of the LaTeX fonts (there are packages
> >>> for this on all linux distros I know, for use with Lyx and you can
> >>> probably find them on the web otherwise) and change all the fonts to
> >>> those once your document is in Inkscape (select all > text and font
> >>> >  select the font)
> >>> 2- or open the document with inkscape and export it to pstricks
> >>> I personally use Inkscape on all my R graphics because I find it
> >>> easier and quicker to get decent graphics and R and refine their
> >>> look  in Inkscape than to get them perfect in R in one shot ( though
> >>> with  ggplot2 things are improving on R's side).
> >
> >> As this works against principles of reproducible research, I wouldn't
> >> recommend it.
> >
> > Do you consider that changing the font size of the graphic would be
> > altering the research result? Or laying out a 2d contour and a 3d plot
>
> Not per se, but accidents happen when editing graphics.  More
> importantly it creates more work.  Datasets get updated/corrected and
> graphics need to be reproduced.
>
> > in parallel, or changing the line color/pattern...? My modifications are
> > usually of this kind. Of course those things are doable with R but they
> > are usually immensely easier in a graphics program (where the color
> > palettes are predefined, the dash patterns are more diverse etc.).
> >
> > For example, I often find myself using the same plot in an article, a
> > presentation, and a poster, usually with different color palettes and
> > font requirements. I just open the pdf, change the colors, font and font
> > size to match the design of the article/presentation/poster, realign the
> > labels a bit and re-save it. I don't think that I am doing any harm to
> > my result or present any false information to the readers, I just make
> > the graphics easier on their eyes.
>
> A great application for a wrapper graphics function with an argument for
> presentation mode.
>
> >
> > But maybe I am a bit too much of a purist on these maters. I just find
> > that, much too often, research results that represent months of work are
> > presented as narrow, black and white (possibly even pixallated!)
> > captures of article graphics which don't do justice to the quality of
> > the work behind them. I don't think there is any harm in making (good)
> > science look a bit "sexier", do you?
>
> Yes there is harm.  But to make bold lines, easy to read titles is fine.
>   See the spar function in
> http://biostat.mc.vanderbilt.edu/SgraphicsHints for a starter.  Also see
> the setps, ps.slide, and setpdf functions in the Hmisc package.

Thanks to all for your thoughts and ideas.

Paul



More information about the R-help mailing list