Created
February 22, 2014 13:33
-
-
Save kohske/9154871 to your computer and use it in GitHub Desktop.
RmdからWordへ...... Enjoy Tikz!!
This file contains 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
# RmdからWordへ | |
と見せかけて、ホントはTikz推しの話。 | |
## RmdからWordへの変換 | |
@teramonagiさんのTokyo R #36での発表 | |
http://www.slideshare.net/teramonagi/tokyo-r36-20140222 | |
を読みましょう。マークダウン + R → ワード。素晴らしいですね。 | |
まず、Rmd、そして、knit、そこで、md、それから、pandoc、そして、word。 | |
これを図で表しましょう。図はTikzで作成します。 | |
```{r diag, engine = "tikz", fig.cap = "RmdからWordへ", fig.ext = 'png', engine.opts=list(template=textConnection("%% TIKZ_CODE %%")), out.width="500px"} | |
\documentclass{ltjsarticle}\usepackage{luatexja}\usepackage{tikz}\usepackage[active,tightpage]{preview}\PreviewEnvironment{tikzpicture} | |
\begin{document} | |
\tikzset{r/.style = {text badly centered, draw, thick, text width=0.18\linewidth, minimum height=0.1\linewidth, minimum width=0.2\linewidth}} | |
\begin{tikzpicture}[node distance=0.33\linewidth, auto] | |
\node [r] (rmd) {Rマークダウン\\(.Rmd)}; | |
\node [r, right of=rmd] (md) {マークダウン\\(.md)}; | |
\node [r, right of=md] (word) {M\$ Word\\(.docx)}; | |
\path [->](rmd) edge node {knit} (md) (md) edge node {pandoc} (word); | |
\end{tikzpicture} | |
\end{document} | |
``` | |
全然関係ないですが、カーリング場も載せておきます。これもTikzで書いています。 | |
```{r cur, engine = "tikz", fig.cap = "RmdからWordへ", fig.ext = 'png', engine.opts=list(template=textConnection("%% TIKZ_CODE %%")), out.width="200px", echo=TRUE} | |
\documentclass{minimal}\usepackage{tikz}\usepackage[active,tightpage]{preview}\PreviewEnvironment{tikzpicture}\begin{document} | |
\begin{tikzpicture} | |
\draw (-12mm, -52mm) rectangle (12mm, 52mm); | |
\foreach \yp in {-40mm, 40mm} { | |
\fill[red] (0, \yp) circle (10mm); | |
\fill[white] (0, \yp) circle (7mm); | |
\fill[blue] (0, \yp) circle (4mm); | |
\fill[white] (0, \yp) circle (1mm); | |
} | |
\draw [thick] (0, -52mm) -- (0, 52mm); | |
\foreach \yp in {-40mm, -20mm, 20mm, 40mm} { | |
\draw [thick] (-12mm, \yp) -- (12mm, \yp); | |
} | |
\fill [white] (-10mm, -10mm) rectangle (10mm, 10mm); | |
\node at (0, 6.5mm) {\textbf{Sochi}}; | |
\definecolor{r1}{RGB}{0,129,188} | |
\definecolor{r2}{RGB}{252,177,49} | |
\definecolor{r3}{RGB}{35,34,35} | |
\definecolor{r4}{RGB}{0,157,87} | |
\definecolor{r5}{RGB}{238,50,78} | |
\begin{scope} | |
\clip (-12mm,-1.7mm) rectangle (12mm, 5mm); | |
\foreach \col/\xp/\yp in { | |
r5/7mm/0, r4/3.5mm/-3mm, r3/0/0, | |
r2/-3.5mm/-2.8mm, r1/-7mm/0 | |
} { | |
\path[draw=white,line width=0.2mm, | |
fill=\col,even odd rule] | |
(\xp, \yp) circle (3.3mm) | |
(\xp, \yp) circle (2.5mm); | |
} | |
\end{scope} | |
\begin{scope} | |
\clip (-12mm,-8.4mm) rectangle (12mm,-1.7mm); | |
\foreach \col/\xp/\yp in { | |
r1/-7mm/0, r2/-3.5mm/-3mm, r3/0/0, | |
r4/3.5mm/-2.8mm, r5/7mm/0 | |
} { | |
\path[draw=white,line width=0.2mm, | |
fill=\col,even odd rule] | |
(\xp, \yp) circle (3.3mm) | |
(\xp, \yp) circle (2.5mm); | |
} | |
\end{scope} | |
\end{tikzpicture} | |
\end{document} | |
``` | |
```{r engine='bash', include=FALSE} | |
convert -density 300 figure/diag.pdf figure/diag.png | |
convert -density 300 figure/cur.pdf figure/cur.png | |
``` | |
## 最後に | |
Enjoy Tikz!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
knit2htmlしたものは http://rpubs.com/kohske/13567