[R] Graphics and LaTeX documents with the same font
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Sat Sep 29 20:39:58 CEST 2007
jiho wrote:
> On 2007-September-28 , at 18:25 , Frank E Harrell Jr wrote:
>> jiho wrote:
>>> On 2007-September-28 , at 16:57 , Frank E Harrell Jr wrote:
>>>> jiho wrote:
>>>>> On 2007-September-28 , at 15:18 , Paul Smith wrote:
>>>>>> On 9/28/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> 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:
>>>>> [...]
>>>>> 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.
>
> I could do that indeed but it would require changing the margins, device
> size, fonts, colors etc. all by hand in R. I am not saying this is
Don't know why "by hand".
> impossible (well in some things are: R may not have access to all the
> fonts in my system, R won't produce print-ready CMYK pdfs etc.) but it
> is just much more trouble than producing one "OK" graphic with R and
> handling the finer presentational details in a program more suited for
> these maters. Not to mention that it would also suppose that I know all
> the presentation requirements in advance, when writing the plotting
> function, which is usually not the case. If I have to redo the plot
> months later I may as well rewrite a new plot script based on the old
> one and go with that.
> Once again I am not saying this is impossible, I am just skeptical about
> the balance between the cost of producing pixel perfect graphics from
> code and the reproducibility benefit associated, particularly in R.
> MATLAB's or Scilab plotting models are more suited in this aspect: the
> plot is represented as an object, that can be saved, with properties
> that you can change _after_ its creation. So it is easy to come back,
> even months after the analysis, and change the colors, the margins etc.
> of the plot and to produce a pdf again. The grids packages goes this way
> fortunately!
We may just have to have a friendly disagreement on these points,
although I don't disagree by much.
Cheers
Frank
>
>>> 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 for the pointers, these functions look useful indeed.
>
> I try to do the more I can in R [1], to reduce Inkscape to the
> fine-tuning (and not risk more error than needed when editing the
> graphics) but eventually, there's always something that does not look
> quite right in R's output, or not consistent between two plots etc. and
> I _have_ to change it in Inkscape (but that is probably the design
> maniac living inside me speaking at this point ;) ).
>
> [1] BTW, for those interested, I extracted the colors of most LaTeX
> Beamer themes:
> http://en.wikipedia.org/wiki/Beamer_(LaTeX)
> and made a Gimp/Inkscape palette with them. I also associated the RGB
> codes with color names in an R script, as well as defined color schemes
> and a few color related functions. You can get everything here:
> http://jo.irisson.free.fr/?p=35
>
> JiHO
> ---
> http://jo.irisson.free.fr/
>
>
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list