[R] autoscaling plot font size in Sweave output possible?
Friedrich.Leisch@tuwien.ac.at
Friedrich.Leisch at tuwien.ac.at
Sat Jan 8 11:52:41 CET 2005
>>>>> On Sat, 08 Jan 2005 03:59:14 +0100,
>>>>> Patrick Drechsler (PD) wrote:
> Hi Friedrich,
> Friedrich Leisch wrote on 07 Jan 2005 09:49:04 MET:
> thanks for taking the time!
>>>>>>> On Thu, 06 Jan 2005 23:56:31 +0100,
>>>>>>> Patrick Drechsler (PD) wrote:
>>> I was wondering if it's possible to have fonts in plots to be
>>> autoscaled to the same font size used by LaTeX in a
>>> surrounding Sweave document.
>>
>> Not using the standard mechanism, because there figures are
>> rescaled *after* they are created, and the font is rescaled
>> together with the rest.
> ..I was afraid of that...
>> What yoy have to do is:
>>
>> 1) Create your own Sweave.sty file
> [...]
> Ok...
>> 2) Explicitly set height and width of each figure chunk to what
>> it should be in the final document. Unfortunately you cannot
>> use any fractions of \textwidth or the like because Sweawe has
>> no means to know what that might be.
> see below...
>> 3) Set the font size to what you use in the tex document using
>> ps.options().
> see below...
> Could you or somebody else enhance my OP in this sence to
> demonstrate the effect intended? I've fiddled around with
> `postscrict' and `ps.options' all day long but haven't reached a
> working file. The problem is most likely sitting in front of the
> keyboard.
>> It is because of 2) that I didn't follow this route for the
>> current defaults, and I haven't found a really convincing
>> alternative which works in "most" situations ...
> Not knowing if it's actually going to help me: Can you point me
> to the file which does the conversion to the *.tex file? I've
> tried `locate sweave' on my linux box and there wasn't anything
> in the results concerning the conversion to TeX.
???
Sweave is part of package utils (which the help page clearly
indicates), the particular driver for Latex is called RweaveLatex and
referenced in the Sweave help page. If you want to have a look at the
source code the easiest thing is to get the R sources and browse in
the sources of package utils ... I'll leave it to you to figure out
which of the files contains the Sweave R code.
> I'm one of those guys that wants to have nice looking results at
> the end with all plots having the same layout.
To me it sounds much more like you're one of those guys who like it
when others solve their problems for free. I gave you an IMO perfectly
working cookbook recipe and you didn't even bother to tell me what did
not work out for you, only a "see below" to completely different
things (export from MATLAB isn't exactly helping me in guessing what
went wrong for you).
As christmas present (mostly to other who bother to follow the thread)
attached a solution that has exactly the same font in plots and normal
text (and was obtained by simply following the recipe I gave in my
earlier email step by step).
Best,
Fritz
* file.Rnw *********************************************************
\documentclass{article}
\newcommand{\mytext}{some x label --- some y label --- some x label
--- some y label}
\usepackage{MySweave}
\usepackage{times}
\begin{document}
\mytext
<<results=hide,echo=false>>=
ps.options(pointsize=10,family="Times")
<<test0,echo=F,fig=T,width=2,height=2>>=
x <- 1:10
y <- sin(x)
plot(x,y,
xlab="some x label",
ylab="some y label"
)
@
\mytext
<<test1,echo=F,fig=T,width=4,height=4>>=
plot(x,y,
xlab="some x label",
ylab="some y label"
)
@ %def
\mytext
\end{document}
* MySweave.sty *******************************************
\RequirePackage[T1]{fontenc}
\RequirePackage{graphicx,ae,fancyvrb}
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
\newenvironment{Schunk}{}{}
More information about the R-help
mailing list