Created
January 19, 2012 19:58
-
-
Save kohske/1642207 to your computer and use it in GitHub Desktop.
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
| \documentclass{beamer} | |
| \usepackage{fontspec} | |
| \setsansfont{Hiragino Kaku Gothic Pro W3} | |
| \setmonofont{Monaco} | |
| \XeTeXlinebreaklocale "ja" | |
| \XeTeXlinebreakskip=0pt plus 1pt | |
| \XeTeXlinebreakpenalty=0 | |
| \def\<{\@ifstar{\zx@hwback\nobreak}{\zx@hwback\relax}} | |
| \def\zx@hwback#1{\leavevmode#1\hskip-.5em\relax}%% LyX 2.1.0svn created this file. For more info, see http://www.lyx.org/. | |
| \usetheme{Rochester} | |
| \ifdefined\knitrout | |
| \renewenvironment{knitrout}{\begin{tiny}}{\end{tiny}} | |
| \else | |
| \fi | |
| \title{R+knitr+beamer+日本語+ggplot2} | |
| \author{たかはしこうすけ} | |
| \date{\today} | |
| \begin{document} | |
| \frame{\titlepage} | |
| \frame{ | |
| \frametitle{はじめに} | |
| \begin{description} | |
| \item[R] 環境。 | |
| \item[knitr] texっぽいものをpdfなどにしてくれるもの。 | |
| \item[beamer] texでプレゼンを作るもの。 | |
| \item[日本語] texの敵。 | |
| \item[ggplot2] グラフづくり。 | |
| \end{description} | |
| } | |
| \frame{ | |
| \frametitle{このスライドの目的} | |
| Rのknitrパッケージを使って、RnwからRコードとggplot2の出力を埋め込んだスライド用のPDFを作り出します。 | |
| \vspace{0.5in} | |
| 見た目はtexの方の機能で調整するんですが、面倒なのでほとんどいじってません。 | |
| } | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{コードの埋め込み+コード表示+実行} | |
| こういう風に書くと | |
| <<echo=FALSE,comment=NA>>= | |
| cat('<<>>= | |
| # create some random numbers | |
| (x=rnorm(20)) | |
| mean(x) | |
| @') | |
| @ | |
| こういう風になります | |
| <<>>= | |
| # create some random numbers | |
| (x=rnorm(20)) | |
| mean(x) | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{コードの埋め込み+実行しない} | |
| 実行しません。 | |
| コード例だけ示したいときに便利。 | |
| <<eval=FALSE>>= | |
| # create some random numbers | |
| (x=rnorm(20)) | |
| mean(x) | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{実行のみ} | |
| コードを表示しません。実行結果だけ表示します。 | |
| レポート等にはコードはいりませんから。 | |
| <<echo=FALSE>>= | |
| # create some random numbers | |
| (x=rnorm(20)) | |
| mean(x) | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{グラフィックス} | |
| グラフィックスも埋め込めます。 | |
| <<fig.keep=all,fig.width=5,fig.height=4,out.height=.4\textwidth,cache=TRUE>>= | |
| par(mar=c(3,3,.1,.1)) | |
| plot(1:10, 1:10, col=1:10) | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{ggplot2} | |
| ggplot2のグラフです。ちなみに次バージョン(0.9)から凡例でカラーバーが使えます。次バージョン、example走らせるのに時間がかかりすぎて、CRANにリジェクトされてしまいました・・・。 | |
| <<fig.keep=all,fig.width=5,fig.height=4,out.height=.4\textwidth,cache=TRUE>>= | |
| library(ggplot2) | |
| qplot(1:10, 1:10, colour = 1:10) + guides(colour = "colorbar") | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{表} | |
| 表のグラフィックオブジェクトです。でも表はtexの機能でやった方がいいかな。 | |
| <<fig.keep=all,fig.width=5,fig.height=3,out.height=.3\textwidth,cache=TRUE>>= | |
| library(gridExtra) | |
| grid.table(head(iris, 6)) | |
| @ | |
| \end{frame} | |
| \begin{frame} | |
| [fragile] | |
| \frametitle{表} | |
| xtableの出力をtexの入力として使うのはどうすんだろう? | |
| <<>>= | |
| library(xtable) | |
| xtable((head(iris, 6))) | |
| @ | |
| \end{frame} | |
| \frame{ | |
| \frametitle{おしまい} | |
| \begin{center} | |
| これは本気でつかえるかも。 | |
| \end{center} | |
| } | |
| \end{document} |
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
| #> library(knitr) | |
| #> options(texi2dvi = "xelatex") | |
| #> knit2pdf("sample.Rnw") | |
| |>>>> | 6% | |
| |>>>>>>>> | 12% | |
| unnamed-chunk-1: echo=FALSE, comment=NA | |
| |>>>>>>>>>>> | 18% | |
| |>>>>>>>>>>>>>>> | 24% | |
| |>>>>>>>>>>>>>>>>>>> | 29% | |
| |>>>>>>>>>>>>>>>>>>>>>>> | 35% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>> | 41% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 47% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 53% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 59% | |
| unnamed-chunk-5: fig.keep=all, fig.width=5, fig.height=4, | |
| out.height=.4\textwidth, cache=TRUE | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 65% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 71% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 76% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 82% | |
| unnamed-chunk-7: fig.keep=all, fig.width=5, fig.height=3, | |
| out.height=.3\textwidth, cache=TRUE | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 88% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 94% | |
| |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100% | |
| ordinary text without R code | |
| output file: /Users/takahashi/tmp/sample.tex |
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
| #> sessionInfo() | |
| R version 2.14.1 (2011-12-22) | |
| Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) | |
| locale: | |
| [1] ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C/ja_JP.UTF-8/ja_JP.UTF-8 | |
| attached base packages: | |
| [1] grid stats graphics grDevices utils datasets methods base | |
| other attached packages: | |
| [1] xtable_1.6-0 gridExtra_0.8.5 ggplot2_0.9.0 knitr_0.1.1 devtools_0.5.1 | |
| loaded via a namespace (and not attached): | |
| [1] codetools_0.2-8 colorspace_1.1-0 dichromat_1.2-4 digest_0.5.1 evaluate_0.4.1 | |
| [6] formatR_0.3-4 highlight_0.3.1 MASS_7.3-16 memoise_0.1 munsell_0.3 | |
| [11] parser_0.0-14 plyr_1.7.1 proto_0.3-9.2 RColorBrewer_1.0-5 Rcpp_0.9.9 | |
| [16] RCurl_1.9-4 reshape2_1.2 scales_0.1.0 stringr_0.6 tools_2.14.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment