-
Notifications
You must be signed in to change notification settings - Fork 0
/
learnR.tex
523 lines (437 loc) · 15.2 KB
/
learnR.tex
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
\documentclass{tufte-book}\usepackage[]{graphicx}\usepackage[]{color}
% maxwidth is the original width if it is less than linewidth
% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
\usepackage{Sweavel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[flexible]{optional}
\usepackage{tufte-larger}
\usepackage[some]{background}
\usepackage{amsmath, amssymb,txfonts,bm}
\usepackage{checkend}
\usepackage{nextpage}
\usepackage{listings}
\usepackage{framed}
\usepackage{alltt}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\usepackage{float}
\usepackage{colortbl}
\usepackage{cprotect}
\usepackage{enumitem}
\usepackage{makeidx}
\makeindex
\usepackage{index}
\usepackage{multicol}
\usepackage{natbib}
\newindex{fun}{fdx}{fnd}{Index of R Symbols and Functions}
\newindex{default}{idx}{ind}{Index of Terms}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\newenvironment{knitrout}{\setlength{\topsep}{0mm}}{}
% \newcommand{\flexicol}{fullflexible}
\newcommand{\flexicol}{fixed}
\lstdefinestyle{Rstyle}{%
fancyvrb=false,escapechar=`,language=R,%
basicstyle={\Rcolor\Sweavesize\ttfamily},% Added \ttfamily
backgroundcolor=\Rbackground,%
showstringspaces=false,%
keywordstyle=\Rcolor,%
commentstyle={\Rcommentcolor\ttfamily\itshape},%
%literate= Removed
alsoother={$},%
alsoletter={.<-},%
otherkeywords={!,!=,~,$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},%
escapeinside={(*}{*)}}%
\makeatletter
\renewenvironment{theindex}{%
\columnseprule \z@
\columnsep 35\p@
\begin{multicols}{3}[\chapter*{\indexname}][10\baselineskip]%
\addcontentsline{toc}{chapter}{\indexname}%
\setlength\parindent{0pt}\pagestyle{plain}\let\item\@idxitem}
{\end{multicols}}
\makeatother
\hypersetup{colorlinks}% uncomment this line if you prefer colored hyperlinks (e.g., for onscreen viewing)
\makeatletter
\newcommand{\subtitle}[1]{
\gdef\@subtitle{#1}
}
\renewcommand{\maketitlepage}[0]{%
\cleardoublepage%
{%
\sffamily%
\begin{fullwidth}%
\fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}%
\vspace{11.5pc}%
\fontsize{24}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklesstitle}}%
\ifdefined\@subtitle
{\fontsize{18}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\@subtitle}}}%
\fi
\vfill%
\fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}%
\end{fullwidth}%
}
\thispagestyle{empty}%
\clearpage%
}
\makeatother
% \renewcommand{\maketitlepage}[0]{%
% \cleardoublepage%
% {%
% \sffamily%
% \begin{fullwidth}%
% \fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{{\thanklessauthor}}%
% \vspace{11.5pc}%
% % \fontsize{27}{30}\selectfont\par\noindent\textcolor{darkgray}{{\thanklesstitle}}%
% \fontsize{40}{45}\selectfont\par\noindent\textcolor{darkgray}{{\thanklesstitle}}%
% \vfill%
% \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}%
% \end{fullwidth}%
% }
% \thispagestyle{empty}%
% \clearpage%
% }
%%
% Book metadata
\title{Learning and Exploring R}
\subtitle{Data Analysis, and More, by Example}
\author[]{J H Maindonald}
\publisher{}
%%
% If they're installed, use Bergamo and Chantilly from www.fontsite.com.
% They're clones of Bembo and Gill Sans, respectively.
%\IfFileExists{bergamo.sty}{\usepackage[osf]{bergamo}}{}% Bembo
%\IfFileExists{chantill.sty}{\usepackage{chantill}}{}% Gill Sans
%\usepackage{microtype}
%%
% For nicely typeset tabular material
\usepackage{booktabs}
%%
% For graphics / images
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{figs/}}
% The fancyvrb package lets us customize the formatting of verbatim
% environments. We use a slightly smaller font.
\usepackage{relsize,fancyvrb}
\fvset{fontsize=\normalsize}
%%
% Prints argument within hanging parentheses (i.e., parentheses that take
% up no horizontal space). Useful in tabular environments.
\newcommand{\hangp}[1]{\makebox[0pt][r]{(}#1\makebox[0pt][l]{)}}
%%
% Prints an asterisk that takes up no horizontal space.
% Useful in tabular environments.
\newcommand{\hangstar}{\makebox[0pt][l]{*}}
%%
% Prints a trailing space in a smart way.
\usepackage{xspace}
%%
% Some shortcuts for Tufte's book titles. The lowercase commands will
% produce the initials of the book title in italics. The all-caps commands
% will print out the full title of the book in italics.
\newcommand{\vdqi}{\textit{VDQI}\xspace}
\newcommand{\ei}{\textit{EI}\xspace}
\newcommand{\ve}{\textit{VE}\xspace}
\newcommand{\be}{\textit{BE}\xspace}
\newcommand{\VDQI}{\textit{The Visual Display of Quantitative Information}\xspace}
\newcommand{\EI}{\textit{Envisioning Information}\xspace}
\newcommand{\VE}{\textit{Visual Explanations}\xspace}
\newcommand{\BE}{\textit{Beautiful Evidence}\xspace}
\newcommand{\TL}{Tufte-\LaTeX\xspace}
% Prints the month name (e.g., January) and the year (e.g., 2008)
\newcommand{\monthyear}{%
\ifcase\month\or January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or
December\fi\space\number\year
}
% Prints an epigraph and speaker in sans serif, all-caps type.
\newcommand{\openepigraph}[2]{%
%\sffamily\fontsize{14}{16}\selectfont
\begin{fullwidth}
\sffamily\large
\begin{doublespace}
\noindent{#1}\\% epigraph
\noindent{#2}% author
\end{doublespace}
\end{fullwidth}
}
% Inserts a blank page
\newcommand{\blankpage}{\newpage\hbox{}\thispagestyle{empty}\newpage}
\usepackage{units}
% Typesets the font size, leading, and measure in the form of 10/12x26 pc.
\newcommand{\measure}[3]{#1/#2$\times$\unit[#3]{pc}}
% Macros for typesetting the documentation
\newcommand{\hlred}[1]{\textcolor{Maroon}{#1}}% prints in red
\newcommand{\hangleft}[1]{\makebox[0pt][r]{#1}}
\newcommand{\hairsp}{\hspace{1pt}}% hair space
\newcommand{\hquad}{\hskip0.5em\relax}% half quad space
\newcommand{\TODO}{\textcolor{red}{\bf TODO!}\xspace}
\newcommand{\ie}{\textit{i.\hairsp{}e.}\xspace}
\newcommand{\eg}{\textit{e.\hairsp{}g.}\xspace}
\newcommand{\na}{\quad--}% used in tables for N/A cells
\providecommand{\XeLaTeX}{X\lower.5ex\hbox{\kern-0.15em\reflectbox{E}}\kern-0.1em\LaTeX}
\newcommand{\tXeLaTeX}{\XeLaTeX\index{XeLaTeX@\protect\XeLaTeX}}
% \index{\texttt{\textbackslash xyz}@\hangleft{\texttt{\textbackslash}}\texttt{xyz}}
\newcommand{\tuftebs}{\symbol{'134}}% a backslash in tt type in OT1/T1
\newcommand{\doccmdnoindex}[2][]{\texttt{\tuftebs#2}}% command name -- adds backslash automatically (and doesn't add cmd to the index)
\newcommand{\doccmddef}[2][]{%
\hlred{\texttt{\tuftebs#2}}\label{cmd:#2}%
\ifthenelse{\isempty{#1}}%
{% add the command to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2}}% command name
}%
{% add the command and package to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2} (\texttt{#1} package)}% command name
\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}% package name
}%
}% command name -- adds backslash automatically
\newcommand{\doccmd}[2][]{%
\texttt{\tuftebs#2}%
\ifthenelse{\isempty{#1}}%
{% add the command to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2}}% command name
}%
{% add the command and package to the index
\index{#2 command@\protect\hangleft{\texttt{\tuftebs}}\texttt{#2} (\texttt{#1} package)}% command name
\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}% package name
}%
}% command name -- adds backslash automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath{\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newenvironment{docspec}{\begin{quotation}\ttfamily\parskip0pt\parindent0pt\ignorespaces}{\end{quotation}}% command specification environment
\newcommand{\docenv}[1]{\texttt{#1}\index{#1 environment@\texttt{#1} environment}\index{environments!#1@\texttt{#1}}}% environment name
\newcommand{\docenvdef}[1]{\hlred{\texttt{#1}}\label{env:#1}\index{#1 environment@\texttt{#1} environment}\index{environments!#1@\texttt{#1}}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}\index{#1 package@\texttt{#1} package}\index{packages!#1@\texttt{#1}}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}\index{#1 class option@\texttt{#1} class option}\index{class options!#1@\texttt{#1}}}% document class option name
\newcommand{\docclsoptdef}[1]{\hlred{\texttt{#1}}\label{clsopt:#1}\index{#1 class option@\texttt{#1} class option}\index{class options!#1@\texttt{#1}}}% document class option name defined
\newcommand{\docmsg}[2]{\bigskip\begin{fullwidth}\noindent\ttfamily#1\end{fullwidth}\medskip\par\noindent#2}
\newcommand{\docfilehook}[2]{\texttt{#1}\index{file hooks!#2}\index{#1@\texttt{#1}}}
\newcommand{\doccounter}[1]{\texttt{#1}\index{#1 counter@\texttt{#1} counter}}
% Generates the index
% \usepackage{makeidx}
% \definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\definecolor{light}{gray}{.9}
\definecolor{gray40}{gray}{.4}
\definecolor{gray80}{gray}{.8}
\definecolor{gray90}{gray}{.9}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\makeatletter
\newenvironment{kframe}{%
\def\at@end@of@kframe{}%
\ifinner\ifhmode%
\def\at@end@of@kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed%
\at@end@of@kframe}
\makeatother
\newcommand{\txtt}[1]{\texttt{#1}}
\newcommand{\code}[1]{\texttt{#1}}
\newcommand{\pkg}[1]{\texttt{#1}}
\newcommand{\margtt}[1]{{\footnotesize \texttt{#1}}}
\lstnewenvironment{verbcode}
{\lstset{language=R, xleftmargin=4pt, frame=single, framerule=0pt,
basicstyle=\small\ttfamily,
columns=\flexicol,
showstringspaces=false, backgroundcolor=\color{light}}}
{}
\newenvironment{itemizz}%
{\begin{itemize} %
\setlength{\itemsep}{2pt}%
\setlength{\parskip}{2pt}} %
{\end{itemize}}
%% \includeonly{0intro,1gettingStarted}
\begin{document}
\include{preamble}
% Front matter
\frontmatter
%
\setsidenotefont{\small}
\setcaptionfont{\small}
\setmarginnotefont{\small}
% \setcitationfont
% \SetBgContents{
% \includegraphics{figs-inc/cover-bg.pdf}
% }
% \SetBgScale{3.5}
% \SetBgColor{gray!70}
% \SetBgOpacity{0.2}
% \BgThispage
\bmdefine\bX{\mathbf{X}}
\bmdefine\bP{\mathbf{P}}
\bmdefine\sfX{\bm{\textsf{\textmd{X}}}}
% \pagestyle{headings}
% r.1 blank page
% \blankpage
% v.2 epigraphs
% r.3 full title page
\maketitle
% v.4 copyright page
\newpage
\begin{fullwidth}
~\vfill
\thispagestyle{empty}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
Copyright \copyright\ \the\year\ \thanklessauthor\\
This text is dual licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC-BY-SA) and the GNU Free Documentation License (GFDL).
% \par\smallcaps{Published by \thanklesspublisher}
% \par\smallcaps{tufte-latex.googlecode.com}
\par\textit{\monthyear}
\end{fullwidth}
\vfill
\thispagestyle{empty}
\openepigraph{%
S has forever altered the way people analyze, visualize, and
manipulate data... S is an elegant, widely accepted, and enduring
software system, with conceptual integrity, thanks to the insight,
taste, and effort of John Chambers.
}{{\itshape From the citation for the 1998 Association for Computing Machinery
Software award.}
}
\vfill
\openepigraph{%
A big computer, a complex algorithm and a long time does not equal
science.
}{Robert Gentleman}
\vfill
%
% r.5 contents
\tableofcontents
% \begin{fullwidth}
% \listoffigures
% \end{fullwidth}
% \listoftables
% r.7 dedication
% \cleardoublepage
% ~\vfill
% \begin{doublespace}
% \noindent\fontsize{18}{22}\selectfont\itshape
% \nohyphenation
% Dedicated to the creators of S and R.
% \end{doublespace}
% \vfill
% \vfill
% r.9 introduction
\cleardoublepage
\chapter*{Introduction}
\include{0intro}
% <<mintro, child='0intro.Rnw'>>=
% @
% Start the main matter (normal chapters)
\mainmatter
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\chapter{Getting started with R}\label{ch:getStart}
\include{1gettingStarted}
% <<mprelim, child='1gettingStarted.Rnw'>>=
% @
% % \cleartooddpage
\chapter{The R Working Environment}\label{ch:workenv}
\include{2rworking}
% <<mrworking, child='2rworking.Rnw'>>=
% @
% \cleartooddpage
\chapter{Data Analysis -- Models and Examples}\label{ch:worked}
\include{3statsExs}
% <<mrexamples, child='3examples.Rnw'>>=
% @
% \cleartooddpage
\chapter{Data Objects and Functions}
\include{4data}
% <<mdata, child='4data.Rnw'>>=
% @
% \cleartooddpage
\chapter{Data Input and Storage}\label{ch:input}
\include{5input}
% <<minput, child='5input.Rnw'>>=
% @
% \cleartooddpage
\chapter{Data Manipulation and Management}\label{ch:manip}
\include{6manip}
% <<mmanip, child='6manip.Rnw'>>=
% @
% \cleartooddpage
\chapter{Graphics -- base, lattice, ggplot2, rgl, googleVis\ldots}\label{ch:plots}
\include{7graphics}
% <<mgraphics, child='7graphics.Rnw'>>=
% @
% \cleartooddpage
\chapter{Regression with Linear Terms and Factors}
\include{8reg}
% <<m8reg, child='8reg.Rnw'>>=
% @
% \cleartooddpage
\chapter[A Miscellany of Models \& Methods]{$^*$A Miscellany of Models \& Methods}
\include{9further}
% <<m9further, child='9further.Rnw'>>=
% @
% \cleartooddpage
% \chapter{Map Overlays and Spatial Modeling}\label{ch:spatial}
% \include{10maps}
% % <<m10maps, child='10maps.Rnw'>>=
% % @
% % \cleartooddpage
\chapter{Brief Notes on Text Mining}\label{ch:tm}
\include{10tm}
% <<m10tm, child='10tm.Rnw'>>=
% @
% \cleartooddpage
\chapter{$^*$Leveraging R Language Abilities }
\include{11lever}
% <<m11lever, child='11lever.Rnw'>>=
% @
\appendix
\chapter{$^*$R System Configuration}\label{ch:sys}
\include{Arsystem}
% <<A-rsystem, child='Arsystem.Rnw'>>=
% @
% \cleartooddpage
\chapter{The R Commander Graphical User Interface}
\include{Brgui}
% <<C-rgui, child='Brgui.Rnw'>>=
% @
% \cleartooddpage
\chapter{The R system --- history, and the path ahead}\label{app:C}
\include{C-aboutR}
\chapter{Color Versions of Selected Graphs}\label{app:D}
\include{Dcolor}
% <<Dcolor, child='Ccolor.Rnw'>>=
% @
\bibliographystyle{daag}
\bibliography{scistatR}
\renewcommand{\indexname}{Index of Functions}
\begin{fullwidth}
\printindex[fun]
\renewcommand{\indexname}{Index of Terms}
\printindex[default]
\end{fullwidth}
%%
%%
\end{document}