This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
presentation.Rmd
315 lines (287 loc) · 14.5 KB
/
presentation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
---
title: "Drawing inside reveal.js presentations"
always_allow_html: yes
output:
revealjs::revealjs_presentation:
theme: serif
transition: slide
center: true
reveal_plugins: ["zoom", "notes"]
self_contained: false
reveal_options:
showNotes: true
previewLinks: true
tint::tintPdf: default
pagedown::html_paged:
toc: false
number_sections: false
---
## Using the `tikz` engine (1)
```{r funky-tikz, engine = "tikz", fig.cap = NULL, fig.env = "@empty", fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg', fig.width=4, echo=FALSE, cache=TRUE}
\usetikzlibrary{arrows}
\begin{tikzpicture}[node distance=2cm, auto,>=latex', thick, scale = 0.5]
\node (P) {$P$};
\node (B) [right of=P] {$B$};
\node (A) [below of=P] {$A$};
\node (C) [below of=B] {$C$};
\node (P1) [node distance=1.4cm, left of=P, above of=P] {$\hat{P}$};
\draw[->] (P) to node {$f$} (B);
\draw[->] (P) to node [swap] {$g$} (A);
\draw[->] (A) to node [swap] {$f$} (C);
\draw[->] (B) to node {$g$} (C);
\draw[->, bend right] (P1) to node [swap] {$\hat{g}$} (A);
\draw[->, bend left] (P1) to node {$\hat{f}$} (B);
\draw[->, dashed] (P1) to node {$k$} (P);
\end{tikzpicture}
```
## Using the `tikz` engine (2)
```{r seismic-focal-mechanism, engine = "tikz", fig.cap = NULL, fig.env = "@empty", fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg', fig.width=5, echo=FALSE, cache=TRUE}
%: see http://www.texample.net/tikz/examples/seismic-focal-mechanism-in-3d-view/
%% helper macros
%: Styles for XYZ-Coordinate Systems
%: isometric South West : X , South East : Y , North : Z
\tikzset{isometricXYZ/.style={x={(-0.866cm,-0.5cm)}, y={(0.866cm,-0.5cm)}, z={(0cm,1cm)}}}
%: isometric South West : Z , South East : X , North : Y
\tikzset{isometricZXY/.style={x={(0.866cm,-0.5cm)}, y={(0cm,1cm)}, z={(-0.866cm,-0.5cm)}}}
%: isometric South West : Y , South East : Z , North : X
\tikzset{isometricYZX/.style={x={(0cm,1cm)}, y={(-0.866cm,-0.5cm)}, z={(0.866cm,-0.5cm)}}}
\begin{tikzpicture} [scale=4, isometricZXY, line join=round,
opacity=.75, text opacity=1.0,%
>=latex,
inner sep=0pt,%
outer sep=2pt,%
]
\def\h{5}
\newcommand{\quadrant}[2]{
\foreach \t in {#1} \foreach \f in {175,165,...,5}
\draw [fill=#2]
({sin(\f - \h)*cos(\t - \h)}, {sin(\f - \h)*sin(\t - \h)}, {cos(\f - \h)})
-- ({sin(\f - \h)*cos(\t + \h)}, {sin(\f - \h)*sin(\t + \h)}, {cos(\f - \h)})
-- ({sin(\f + \h)*cos(\t + \h)}, {sin(\f + \h)*sin(\t + \h)}, {cos(\f + \h)})
-- ({sin(\f + \h)*cos(\t - \h)}, {sin(\f + \h)*sin(\t - \h)}, {cos(\f + \h)})
-- cycle;
}
%Quadrants
\quadrant{220,230,...,300}{black}
\quadrant{-60,-50,...,20}{white}
\quadrant{30,40,...,120}{black}
\quadrant{130,140,...,210}{none}
%Movement arrows
\foreach \t in {225,235,...,295}
\foreach \f in {50,40,...,0}
\draw [red, opacity=1.0, ->, thick]
({sin(\f - \h)*cos(\t - \h)}, {sin(\f - \h)*sin(\t - \h)}, {cos(\f - \h)})
-- ({(1 + 0.2*cos(90 - \f))*sin(\f - \h)*cos(\t - \h)},
{(1 + 0.2*cos(90 - \f))*sin(\f - \h)*sin(\t - \h)},
{(1 + 0.2*cos(90 - \f))*cos(\f - \h)});
\foreach \t in {125,135,...,205}
\foreach \f in {110,100,...,0}
\draw [black, ->, thick]
({(1 + 0.2*cos(90 - \f))*sin(\f - \h)*cos(\t - \h)},
{(1 + 0.2*cos(90 - \f))*sin(\f - \h)*sin(\t - \h)},
{(1 + 0.2*cos(90 - \f))*cos(\f - \h)})
-- ({sin(\f - \h)*cos(\t - \h)},{sin(\f - \h)*sin(\t - \h)},{cos(\f - \h)});
\foreach \t in {35,45,...,115}
\foreach \f in {130,120,...,0}
\draw [red, opacity=1.0 ,->, thick]
({sin(\f - \h)*cos(\t - \h)}, {sin(\f - \h)*sin(\t - \h)}, {cos(\f - \h)})
-- ({(1 + 0.2*cos(90 - \f))*sin(\f - \h)*cos(\t - \h)},
{(1 + 0.2*cos(90 - \f))*sin(\f - \h)*sin(\t - \h)},
{(1 + 0.2*cos(90 - \f))*cos(\f - \h)});
\foreach \t in {-55,-45,...,25}
\foreach \f in {130,120,...,0}
\draw [black, ->, thick]
({(1 + 0.2*cos(90 - \f))*sin(\f - \h)*cos(\t - \h)},
{(1 + 0.2*cos(90 - \f))*sin(\f - \h)*sin(\t - \h)},
{(1 + 0.2*cos(90 - \f))*cos(\f - \h)})
-- ({sin(\f - \h)*cos(\t - \h)},{sin(\f - \h)*sin(\t - \h)},{cos(\f - \h)});
%Annotations
\path ({1.5*sin(100)*cos(75)}, {1.5*sin(100)*sin(75)}, {1.5*cos(100)}) node [right] {Compression};
\path ({1.5*sin(70)*cos(-15)}, {1.5*sin(70)*sin(-15)}, {1.5*cos(70)}) node [right] {Dilatation};
\path ({1.25*sin(50)*cos(165)},{1.25*sin(50)*sin(165)},{1.25*cos(50)}) node [left] {Dilatation};
\path ({1.25*sin(30)*cos(255)},{1.25*sin(30)*sin(255)},{1.25*cos(30)}) node [left] {Compression};
%P and T axis
\begin{scope}[ultra thick]
\draw[->] ({1.75*sin(90)*cos(75)}, {1.75*sin(90)*sin(75)}, {1.75*cos(90)})
-- ({2*sin(90)*cos(75)},{2*sin(90)*sin(75)},{2*cos(90)}) node [above] {T-axis};
\draw[->] ({1.75*sin(90)*cos(255)},{1.75*sin(90)*sin(255)},{1.75*cos(90)})
-- ({2*sin(90)*cos(255)},{2*sin(90)*sin(255)},{2*cos(90)}) node [below] {T-axis};
\draw[<-] ({1.5*sin(90)*cos(-15)}, {1.5*sin(90)*sin(-15)}, {1.5*cos(90)})
-- ({1.75*sin(90)*cos(-15)},{1.75*sin(90)*sin(-15)},{1.75*cos(90)}) node [right] {P-axis};
\draw[<-] ({1.5*sin(90)*cos(165)}, {1.5*sin(90)*sin(165)}, {1.5*cos(90)})
-- ({1.75*sin(90)*cos(165)},{1.75*sin(90)*sin(165)},{1.75*cos(90)}) node [left] {P-axis};
\end{scope}
% Label
\node [anchor=north, yshift=-2mm] at (current bounding box.south)
{Seismic focal mechanism and Pression-Tension axis.};
\end{tikzpicture}
```
## More `tikz` Engine Links
- [official knitr example](https://github.com/yihui/knitr-examples/blob/master/058-engine-tikz.Rmd)
- [Using tikz in html_document using RMarkdown](https://stackoverflow.com/questions/41143295/using-tikz-in-html-document-using-rmarkdown)
- [Using tikz graphdrawing library within RMarkdown … Need to use lualatex engine, but can't get it to work](https://stackoverflow.com/questions/49212269/using-tikz-graphdrawing-library-within-rmarkdown-need-to-use-lualatex-engine)
- [Include TikZ code in bookdown figure environment](https://stackoverflow.com/questions/47358934/include-tikz-code-in-bookdown-figure-environment)
## Using `tikzDevice`
```{r,engine='tikz', fig.cap = NULL, fig.env = "@empty", fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg', fig.width=10, echo=FALSE, cache=TRUE}
%: see http://www.texample.net/tikz/examples/textronics-oscilloscope/
\def\scl{0.6}%scaling factor of the picture
\begin{tikzpicture}[
scale=\scl,
controlpanels/.style={yellow!30!brown!20!,rounded corners,draw=black,thick},
screen/.style={green!50!black!60!,draw=black,thick},
trace/.style={green!60!yellow!40!, ultra thick},
smallbutton/.style={white,draw=black, thick},
axes/.style={thick}]
\fill[green!30!blue!30!,rounded corners,draw=black,thick](0,0)
rectangle (27.75,13.25);
\fill[fill=black!40!,draw=black,thick,rounded corners](0.25,0.25)
rectangle (27.5,13.00);
% Screen, centered around the origin then shifted for easy plotting
\begin{scope}[xshift=7cm,yshift=8cm,samples=150]
\fill[black!60!,rounded corners,draw=black,thick](-5.3,-4.3)
rectangle (5.3,4.3);
\fill[screen] (-5.0,-4.0) rectangle (5.0,4.0);
\draw[trace] plot(\x,{1+2.4*sin((2.5*\x +1) r)}); % r for radians...
\draw[trace] plot(\x,{-1+1.25*sin((0.75*\x) r});
\draw[thin] (-5.0,-4.0) grid (5.0,4.0);
\draw[axes] (-5,0)--(5,0); % Time axis
\draw[axes] (0,-4)--(0,4);
\foreach \i in {-4.8,-4.6,...,4.8} \draw (\i,-0.1)--(\i,0.1);
\foreach \i in {-3.8,-3.6,...,3.8} \draw (-0.1,\i)--(0.1,\i);
\end{scope}
% Feet
\fill[black!70!,rounded corners,xshift=2cm] (0,-.5) rectangle (2,0);
\fill[black!70!,rounded corners,xshift=23.75cm] (0,-.5) rectangle (2,0);
% Lower left panel
\fill[controlpanels] (0.6,0.5) rectangle (13.5,3.0);
\path (0.8,0.9) node[scale=\scl,right]{$\mathbf{TeXtronics\,1 - v.1.01}$};
% Lower right panel
\fill[controlpanels] (13.7,0.5) rectangle (27.1,6.2);
%Channels
% CH I
\draw[thick] (14.8,1.5) circle (0.7cm);
\fill[gray,draw=black,thick] (14.8,1.5) circle (0.5cm);
\fill[white,draw=black,thick] (14.8,1.5) circle (0.3cm);
\node[scale={1.5*\scl}] at (14.8,2.5) {CH I};
\draw[thick] (16.2,1.5) circle (0.4cm);
\fill[black!60!] (16.2,1.5) circle (0.3cm);
\draw[thick] (16.6,1.5) --(17,1.5)--(17,1.0);
\draw[thick] (16.7,1.0)--(17.3,1.0);
\draw[thick] (16.8,0.85)--(17.2,0.85);
\draw[thick] (16.9,0.70)--(17.1,0.70);
\draw[thick] (26.0,1.5) circle (0.7cm);
% CH II
\fill[gray,draw=black,thick] (26,1.5) circle (0.5cm);
\fill[white,draw=black,thick] (26,1.5) circle (0.3cm);
\node[scale={1.5*\scl}] at (26,2.5) {CH II};
\draw[thick] (24.6,1.5) circle (0.4cm);
\fill[black!60!] (24.6,1.5) circle (0.3cm);
\draw[thick] (24.2,1.5) --(23.7,1.5)--(23.7,1.0);
\draw[thick] (23.4,1.0)--(24.0,1.0);
\draw[thick] (23.5,0.85)--(23.9,0.85);
\draw[thick] (23.6,0.70)--(23.8,0.70);
\draw[thick] (26.0,1.5) circle (0.7cm);
% Y-pos
\fill[smallbutton] (14.8,4.9) circle (0.3cm);
\node[scale={\scl}] at (14.8,5.5) {Y-pos I};
\fill[smallbutton] (26.0,4.9) circle (0.3cm);
\node[scale={\scl}] at (26.0,5.5) {Y-pos II};
% Volt/div the foreach loop draws the two buttons
\foreach \i / \b in {18/75,22.5/345}{
%Second parameter of the loop is the angle of the index mark
\begin{scope}[xshift=\i cm,yshift=3.8cm,scale=0.85]
\node[scale=\scl] at (0,2.3) {Volts/Div};
\node[scale=\scl,black] at (-1,-2.4) {V};
\node[scale=\scl,blue] at (1,-2.4) {mV};
\clip[rounded corners] (-2,-2) rectangle (2,2);
\fill[black!30!,rounded corners,draw=black,thick] (-2,-2)
rectangle (2,2);
\fill[blue!50!black!20!,draw=black,thick]
(30:1.1)--(30:3)--(3,-3)--(-90:3)--(-90:1.1) arc (-90:30:1.1);
\draw[very thick,rounded corners](-2,-2) rectangle (2,2);
\draw[thick] (0,0) circle (1.0);
\foreach \i in {0,30,...,330}
\draw[thick] (\i:1.2)--(\i:2.5);
\foreach \i/\j in {15/50,45/.1,75/.2,105/.5,135/1,165/2,195/5,225/10,
255/20,285/5,315/10,345/20} \node[scale=\scl,black] at (\i:1.7) {\j};
\fill[blue!30!black!60!,draw=black,thick] (0,0) circle (0.8cm);
% Here you set the right Volts/Div button
\draw[ultra thick,red] (\b:0.3)--(\b:1.2);
\end{scope}}
% Upper right panel
\fill[controlpanels] (13.7,6.5) rectangle (27.1,12.75);
%On-Off button
\draw[rounded corners,thick,blue] (13.9,10.5) rectangle (15.9,12.5);
\fill[fill=red,draw=black,thick,rounded corners] (14.4,10.8) rectangle (15.3,11.2);
\node[scale=\scl] at (14.8,12) {\textbf{Power}};
\node[scale=\scl] at (14.8,11.5) {\textbf{On/Off}};
% Focus-Intensity buttons
\draw[rounded corners,thick,blue] (13.9,7.0) rectangle (15.9,10.0);
\fill[smallbutton] (14.9,7.5) circle (0.3cm);
\node[scale=\scl] at (14.9,8.2) {\textbf{Focus}};
\fill[smallbutton] (14.9,9) circle (0.3cm);
\node[scale=\scl] at (14.9,9.6) {\textbf{Intens}};
% X-pos
\fill[smallbutton] (24.5,9.9) circle (0.3cm);
\node[scale={\scl}] at (24.5,10.5) {X-pos};
% Time/Div
\begin{scope}[xshift=21cm,yshift=9.5cm,scale=1]
\node[scale={1.25*\scl}] at (0,2.4) {Time/Div};
\clip[rounded corners] (-2.2,-2) rectangle (2.2,2);
\fill[black!30!,rounded corners,draw=black,thick] (-2.2,-2) rectangle (2.2,2);
\fill[blue!50!black!20!,draw=black,thick]
(45:1.1)--(45:3)--(3,-3)--(-90:3)--(-90:1.1) arc (-90:45:1.1);
\fill[green!50!black!40!,draw=black,thick]
(45:1.1)--(45:3) arc(45:207:3) --(207:1.1) arc (207:45:1.1);
\draw[very thick,rounded corners](-2.2,-2) rectangle (2.2,2);
\node[scale={1.25*\scl}] at (-1.6,-1.6) {$s$};
\node[scale={1.25*\scl}] at (1.6,-1.6) {$\mu{}\,s$};
\node[scale={1.25*\scl}] at (-1.6,1.6) {$m\,s$};
\draw[thick] (0,0) circle (1.0);
\foreach \i in {-72,-54,...,262} \draw[thick] (\i:1.15)--(\i:1.35);
\foreach \i/\j in {-72/.5,-54/1,-36/2,-18/5,0/10,18/20,36/50,54/.1,72/.2,90/.5,
108/1,126/2,144/5,162/10,180/20,198/50,216/.1,234/.2,252/.5}
\node[scale=\scl,black] at (\i:1.7){\j};
\fill[blue!30!black!60!,draw=black,thick] (0,0) circle (0.8cm);
% Here you set the Time/Div button
\draw[ultra thick,red] (-18:0.3)--(-18:1.2);
% X-pos
\end{scope}
\end{tikzpicture}
```
## More `tikzDevice` Links
- [Best Practice for nice layout with tikzDevice](https://tex.stackexchange.com/questions/169354/best-practice-for-nice-layout-with-tikzdevice)
- [knitr documents with tikzDevice graphics](https://www.r-bloggers.com/knitr-documents-with-tikzdevice-graphics/)
- [Latex + R + tikzDevice = Ggplots beautifully integrated in latex documents](https://iltabiai.github.io/tips/latex/2015/09/15/latex-tikzdevice-r.html)
## DiagrammeR
```{r, echo=FALSE, fig.cap = NULL, fig.env = "@empty", out.width="100%"}
# https://mikeyharper.uk/flowcharts-in-r-using-diagrammer/
img.d<-"digraph {
graph [layout = dot, rankdir = LR, bgcolor=transparent]
# define the global styles of the nodes. We can override these in box if we wish
node [shape = rectangle, style = filled, fillcolor = Linen]
data1 [label = 'Dataset 1', shape = folder, fillcolor = Beige]
data2 [label = 'Dataset 2', shape = folder, fillcolor = Beige]
process [label = 'Process \n Data']
statistical [label = 'Statistical \n Analysis']
results [label= 'Results']
# edge definitions with the node IDs
{data1 data2} -> process -> statistical -> results
}"
if (knitr:::is_latex_output()) {
img.d2 <- DiagrammeR::grViz(img.d)
tmp<-capture.output(rsvg::rsvg_png(charToRaw(DiagrammeRsvg::export_svg(img.d2)),'img.png', width=2000))
knitr::include_graphics('img.png')
} else {
DiagrammeR::grViz(img.d)
}
```
## More GraphViz Links
- [GraphViz Pocket Reference](https://graphs.grevian.org/)
- [cannot output any DiagrammeR graph to a pdf file through knitr](https://github.com/rich-iannone/DiagrammeR/issues/133)
## More reveal.js Links
- [R Markdown documentation](https://bookdown.org/yihui/rmarkdown/revealjs.html)
- [Package](https://github.com/rstudio/revealjs) [documentation](https://cran.r-project.org/web/packages/revealjs/revealjs.pdf)
- [Using the `Note:` seperator is currently not possible](https://github.com/rstudio/revealjs/issues/45); instead use <aside class="notes">This is a speaker note</aside>
- [Adding other plugins](https://github.com/rstudio/revealjs/issues/33#issuecomment-231985734)
<aside class="notes">Notes are possible!</aside>