Created
February 11, 2012 20:07
-
-
Save yihui/1803930 to your computer and use it in GitHub Desktop.
Another minimal beamer example for knitr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% this is a simplified version of | |
% https://github.com/yihui/knitr/blob/master/inst/examples/knitr-beamer.Rnw | |
\documentclass{beamer} | |
\begin{document} | |
<<setup, include=FALSE>>= | |
# smaller font size for chunks | |
opts_chunk$set(size = 'footnotesize') | |
@ | |
\title{A Minimal Demo of knitr} | |
\author{Paul Hiemstra \and Yihui Xie} | |
\maketitle | |
% very important to use option [fragile] for frames containing code output! | |
\begin{frame}[fragile] | |
You can test if \textbf{knitr} works with this minimal demo. OK, let's | |
get started with some boring random numbers: | |
<<boring-random>>= | |
set.seed(1121) | |
(x=rnorm(20)) | |
mean(x);var(x) | |
@ | |
\end{frame} | |
\begin{frame}[fragile] | |
The first element of \texttt{x} is \Sexpr{x[1]}. Boring boxplots | |
and histograms recorded by the PDF device: | |
<<boring-plots, fig.width=5, fig.height=5, out.width='.45\\linewidth', fig.show='hold'>>= | |
## two plots side by side (option fig.show='hold') | |
boxplot(x) | |
hist(x,main='') | |
@ | |
\end{frame} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you have a beamer example with references working properly for figures and tables?
The reference bit works, but the label does not print in the figure caption:
<<Figure1, fig.cap = 'My Figure'>>=
...etc.
plot(x, y)
@
\end{frame}
The above has a caption like: Figure: My Figure instead of Figure 1: My Figure
This \ref{fig:Figure1} prints as Figure 1, as expected.
And how to do the same with a table, e.g.
<<Table1, echo = FALSE, results = 'asis'>>=
library(xtable)
xtable(summary(lm(y~x))$coefficients, caption ="Summary")
@
Couldn't get it to work at all inside the beamer class.
Thanks!