-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtextplotPresentation-CRUG-2011.Rnw
341 lines (287 loc) · 9.5 KB
/
textplotPresentation-CRUG-2011.Rnw
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
% $Id$
\documentclass[10pt,presentation]{beamer} %usletter handout
%\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
% may need full path to find these .sty files outside of R environment
\usepackage{Sweave}
% \usepackage{/usr/lib/R/share/texmf/Sweave}
\SweaveOpts{engine=R, eps=FALSE, width=8, height=5}
%\VignetteIndexEntry{How to Present Tables in Plot Devices}
%\VignetteDepends{PerformanceAnalytics}
%\VignetteKeywords{returns, performance, risk, benchmark, portfolio}
%\VignettePackage{PerformanceAnalytics}
% - Talk at a conference/colloquium.
% - Talk length is about 60min.
% Beamer Presentation Template Copyright 2004 by Till Tantau <tantau@users.sourceforge.net>.
% Contents Copyright 2007 Peter Carl and Brian G. Peterson
%
% This file can be redistributed and/or modified under
% the terms of the GNU Public License, version 2.
\mode<presentation>
{
% \usetheme{default}
\usetheme[secheader]{Boadilla}
\usecolortheme{seagull}
% or ...
% \setbeamercovered{transparent}
% or whatever (possibly just delete it)
}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
%%\usepackage{noweb}
\usepackage{subfigure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[english]{babel}
\makeatother
\usepackage[latin1]{inputenc}
% or whatever
\usepackage{lmodern}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\usefonttheme{structurebold}
\title[textplot] % (optional, use only with long paper titles)
{How to Present Tables in Plot Devices}
% \subtitle
% {Include Only If Paper Has a Subtitle}
\author[Peter Carl] % (optional, use only with lots of authors)
{Peter~Carl}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
% affiliation.
\institute[PerformanceAnalytics, etc.] % (optional, but mostly needed)
%{} %the formatting of our companies is likely to be all screwed up
\date[June 2011] % (optional, should be abbreviation of conference name)
{Chicago R User Group Meetup: R Output}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
% yourself) who are reading the slides online
\subject{How to Present Tables in Plot Devices}
% This is only inserted into the PDF information catalog. Can be left
% out.
% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:
% \pgfdeclareimage[height=0.5cm]{university-logo}{university-logo-filename}
% \logo{\pgfuseimage{university-logo}}
% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
% \AtBeginSubsection[]
% {
% \begin{frame}<beamer>
% \frametitle{Outline}
% \tableofcontents[currentsection,currentsubsection]
% \end{frame}
% }
% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:
%\beamerdefaultoverlayspecification{<+->}
\begin{document}
%\right] \right\rbrace \right\rangle \right( \begin{document}
% this has to be after \begin{document} to work
\setkeys{Gin}{width=1\textwidth}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{Outline}
\tableofcontents
% You might wish to add the option [pausesections]
\end{frame}
%%% Section --------------------------------------------------
\section{Overview}
%%% Section --------------------------------------------------
%\subsection{Objectives}
\begin{frame}
\frametitle{Overview}
Graphics in R are plotted on a graphics device
\begin{itemize}
\item
Depending on the OS, in an interactive R session the default device is the screen, using \texttt{windows()}, \texttt{X11()}, or \texttt{quartz()}.
\item
Common graphics file formats use the \texttt{bmp()}, \texttt{jpeg()}, \texttt{png()}, and \texttt{tiff()} devices.
\item
Other useful file devices include \texttt{postscript()}, \texttt{pdf()}, \texttt{pictex()}, \texttt{xfig()}, and \texttt{bitmap()}.
\end{itemize}
Why would we display tabular data on a plot device?
\begin{itemize}
\item
Reviewing results in a terminal isn't usually effective
\item
Garner benefits from formatting
\item
Combining graphics and tables can be very powerful
\end{itemize}
Some solutions, with a focus on \texttt{textplot}
\end{frame}
%%% Section --------------------------------------------------
\section{Example}
%%% Section --------------------------------------------------
\begin{frame}[fragile]
\frametitle{Set up an example}
\begin{figure}
\centering
\begin{scriptsize}
<<Prelim,echo=TRUE,fig=FALSE>>=
library('PerformanceAnalytics')
data(managers)
#managers=read.csv("/home/peter/dev/R/managers.csv",row.names=1)
head(managers)
dim(managers)
colnames(managers)
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Set up an example}
\begin{figure}
\centering
\begin{scriptsize}
<<Prelim,echo=TRUE,fig=FALSE>>=
manager.col = 1
peers.cols = c(2,3,4,5,6)
indexes.cols = c(7,8)
Rf.col = 10
peer.colorset=c("red", rep("darkorange", 2), rep("gray", 5))
ham1.downside = t(table.DownsideRisk(managers[,c(manager.col,
indexes.cols, peers.cols)],Rf=.03/12))
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Construct a table example}
\begin{figure}
\centering
\begin{scriptsize}
<<ConstructTableEx,echo=TRUE,fig=FALSE>>=
ham1.downside
@
\end{scriptsize}
\end{figure}
\end{frame}
%%% Section --------------------------------------------------
\section{Potential Solutions}
%%% Section --------------------------------------------------
\begin{frame}
\frametitle{\texttt{gplots:::textplot}}
Gregory R. Warnes' package, \texttt{gplots}, includes the \texttt{textplot} function
\begin{itemize}
\item
Displays text output in a graphics window
\item
Provides the equivalent of \texttt{print}
\item
Creates a new \texttt{plot} and displays a table using the largest font that will fit in the plotting region
\item
Several other good things in the package, too
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{gplots:::textplot} example}
\begin{figure}
\centering
\begin{scriptsize}
<<gplotstextplot,echo=TRUE,fig=TRUE>>=
library(gplots)
#args(gplots:::textplot)
gplots:::textplot(ham1.downside); box(col="lightblue")
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{\texttt{Hmisc:::format.df}}
The \texttt{Hmisc} package by Frank E. Harrell, Jr., and Richard M. Heiberger contains several functions useful for data analysis
\begin{itemize}
\item
Includes functions for advanced table making, character string manipulation, and conversion of S objects to LaTeX code, and many others.
\item
\texttt{format.df} does rounding and decimal alignment for data.frames, similar to \texttt{format} in \texttt{base}
\item
Generates a character matrix containing the formatted data
\item
Useful for formating tables in LaTeX or HTML, as well
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{Hmisc:::format.df} example}
\begin{figure}
\centering
\begin{scriptsize}
<<Hmiscformat,echo=TRUE,fig=FALSE>>=
library(Hmisc)
args(format.df)
ham1.f.downside = format.df(ham1.downside, na.blank=TRUE, numeric.dollar = FALSE, cdec=rep(4,dim(ham1.downside)[2]))
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{Hmisc:::format.df} example}
\begin{figure}
\centering
\begin{scriptsize}
<<Hmiscformat,echo=TRUE,fig=FALSE>>=
ham1.f.downside
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{\texttt{PerformanceAnalytics:::textplot}}
The \texttt{PerformanceAnalytics} package extends the \texttt{gplots:::textplot} function
\begin{itemize}
\item
Equivalent of \texttt{print} except that the output is displayed as a plot
\item
Fixes some of the layout math
\item
Adds column and row name word wrapping
\item
Adds color to the table elements
\item
Adds vertical alignment for headers and data
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{PerformanceAnalytics:::textplot} example}
\begin{figure}
\centering
\begin{scriptsize}
<<PAtextplot, echo=TRUE, fig=FALSE>>=
require(PerformanceAnalytics)
args(PerformanceAnalytics:::textplot)
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{PerformanceAnalytics:::textplot} example}
\begin{figure}
\centering
\begin{scriptsize}
<<PAtextplot, echo=TRUE, fig=TRUE>>=
PerformanceAnalytics:::textplot(ham1.f.downside, halign = "center", valign = "top", row.valign="center", col.rownames=peer.colorset, mar = c(0,0,3,0)+0.1)
box(col="lightblue")
@
\end{scriptsize}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Other Possibilities}
What else is available?
\begin{itemize}
\item
A very promising package presented at useR! 2010, \texttt{tabulaR}
\item
Dump results to a spreadsheet, perhaps with \texttt{XLConnect}
\item
Finally learn \LaTeX ~and Sweave
\item
What did I miss? Any feedback would be much appreciated \ldots
\end{itemize}
\end{frame}
%%% END OF DOCUMENT --------------------------------------------------
\end{document}