\documentclass[a4paper] {jsarticle}
\AtBeginDocument{\special{pdf: pagesize width \the\paperwidth\space height \the\paperheight}}
\usepackage[dvipdfm]{graphicx}
\usepackage{txfonts}
\usepackage{mediabb}
\usepackage{booktabs}

\setlength{\textwidth}{49zw}
\setlength{\oddsidemargin}{0mm}
\setlength{\voffset}{-25mm}
\setlength{\textheight}{255mm}% default 225mm

\newcommand{\func}[1]{\texttt{#1()}}
\newcommand{\code}[1]{{\texttt{#1}}}
\newcommand{\R}{{\normalfont\textsf{R }}{}}

\title{Mac OS X+TeXShop+UpTeX+Sweave $\rightarrow$ PDF ファイル}
\date{}

\begin{document}

\maketitle

\SweaveOpts{keep.source=TRUE}
%\setkeys{Gin}{width=320bp}

図を描くには，\code{Sweave.engine} 中に定義した \func{xfigure} を使う。

第1引数に図を描くコードをシングルクオートでくくって書く。

第2引数は図のタイトルである。

第1引数のコードで描かれるファイルは，この \code{.Rnw} のあるディレクトリの \code{figure} ディレクトリに作られる。
ファイル名は，\func{xfigure} の第3引数に拡張子 \code{.pdf} を付けたものになる（例では \code{figure/label.pdf}）。第3引数は \LaTeX の \code{\textbackslash label\{\}} の引数に兼用される。

以下のコードで描かれたのが，図\ref{label}である。

<<results=tex>>=
xfigure('
plot(Sepal.Length ~ Petal.Length, data=iris, col=iris$Species)
abline(lm(Sepal.Length ~ Petal.Length, data=iris), col="blue")
', '図のタイトル', 'label', height=1)
@

\begin{table}[htbp]
	\begin{center}
		\caption{\func{xfigure} の引数}
		\label{args}
		\begin{tabular}{p{12zw}p{30zw}} \hline
			引数とデフォルト & 説明 \\ \hline
			\code{src} &	プログラム文字列\\
			\code{caption = "caption"} & 図のタイトル\\
			\code{fn} & ファイル名（\LaTeX の \code{\textbackslash label\{\}} のデフォルト）\\
			\code{label = fn} & デフォルトではない \code{\textbackslash label\{\}}\\
			\code{base = "figure"} & 画像ファイルを置くサブディレクトリ名\\
			\code{size = 320} & \LaTeX 文書中の図の横幅（bp）\\
			\code{width = size*6/320} & 画像ファイルの横幅（ピクセル）\\
			\code{height = 2/3} & 画像ファイルの横幅に対する縦の割合\\
			\code{mgp = c(1.8, 0.6, 0)} & \code{par} で指定する \code{mgp}\\
			\code{mar = c(3, 3, 1, 1)} &  \code{par} で指定する \code{mar}\\
			\code{rev = -3} & 図のと表題の間隔の調整（ポイント）\\
			\code{htbp = "htbp"} & \LaTeX の \code{htbp}\\ \hline
		\end{tabular}
	\end{center}
\end{table}

\end{document}
