15

ビーマー+スウィーブを使用してggplot2グラフィックスでプレゼンテーションを作成しようとしています。一部のスライドには 2 つの列が必要です。左がコード、右が結果のグラフィックです。これが私が試したことです、

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/Sweave}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{amsmath,amssymb}% AMS standards
\usepackage{listings}
\usetheme{Madrid}
\usecolortheme{dove}
\usecolortheme{rose}
\SweaveOpts{pdf=TRUE, echo=FALSE, fig=FALSE, eps=FALSE, tidy=T, width=4, height=4}

\title{Reproducible data analysis with \texttt{ggplot2} \& \texttt{R}}
\subtitle{subtitle}
\author{Baptiste Augui\'e}
\date{\today}
\institute{Here}

\begin{document}

\begin{frame}[fragile]
  \frametitle{Some text to show the space taken by the title}
\begin{columns}[t] \column{0.5\textwidth}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
\column{0.5\textwidth}  
\begin{figure}[!ht]
\centering
<<fig=TRUE>>=
grid.rect(gp=gpar(fill="slateblue"))
@
\end{figure}
\end{columns}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Some text to show the space taken by the title}
\begin{columns}[t] 
  \column{0.5\textwidth}
<<echo=TRUE,fig=FALSE>>=
library(ggplot2)
p <- 
qplot(mpg, wt, data=mtcars, colour=cyl) + 
  theme_grey(base_family="Helvetica")
@
\column{0.5\textwidth}  
\begin{figure}[!ht]
\centering
<<fig=TRUE>>=
print(p)
@
\end{figure}
\end{columns}
\end{frame}

\end{document}

そして、出力の2ページ。

先頭ページ

2ページ目

この出力には 2 つの問題があります。

  • echo-ed sweave コードは列環境を無視し、2 つの列にまたがります

  • いずれかのグラフィックの列余白が不必要に広い

何か案は?

ありがとう。

4

1 に答える 1

12
  • 最初の質問に関しては、keep.source=TRUESweaveOpts で設定するのが簡単な方法です。より高度な制御についてはfancyvrb、Sweave マニュアルの FAQ #9 を参照してください。
  • Figure の幅は、\setkeys{Gin}{width=1.0\textwidth}

ここにわずかな変更があります:

... snip ...

\SweaveOpts{pdf=TRUE, echo=FALSE, fig=FALSE, eps=FALSE, tidy=T, width=4, height=4, keep.source=TRUE}

\title{Reproducible data analysis with \texttt{ggplot2} \& \texttt{R}}

... snip ...


\begin{document}
\setkeys{Gin}{width=1.1\textwidth}

... snip...

<<echo=TRUE,fig=FALSE>>=
library(ggplot2)
p <- 
  qplot(mpg,
        wt,
        data=mtcars,
        colour=cyl) +  
  theme_grey(base_family=
             "Helvetica")
@

ここに画像の説明を入力

于 2011-08-06T06:15:28.687 に答える