diff --git a/Guide-concordance.tex b/Guide-concordance.tex index 5cf5469..e7bd9c2 100644 --- a/Guide-concordance.tex +++ b/Guide-concordance.tex @@ -1,3 +1,4 @@ \Sconcordance{concordance:Guide.tex:Guide.Rnw:% -1 79 1 50 0 4 1 1 32 9 1 1 7 9 1 1 5 93 1 1 7 171 1 26 0 13 1 24 0 % -14 1 20 0 16 1 17 0 57 1 15 0 26 1 21 0 358 1 4 0 10 1 1 7 66 1} +1 79 1 50 0 4 1 1 32 9 1 1 7 9 1 1 5 93 1 1 7 159 1 26 0 14 1 24 0 % +15 1 20 0 16 1 17 0 57 1 15 0 26 1 21 0 175 1 11 0 13 1 30 0 11 1 % +22 0 22 1 21 0 325 1 4 0 10 1 1 7 66 1} diff --git a/Guide.Rnw b/Guide.Rnw index efd900d..355bc8a 100644 --- a/Guide.Rnw +++ b/Guide.Rnw @@ -253,8 +253,8 @@ From our dataset DATA, we graph the variable \emph{Year} on the x-axis and the v \begin{verbatim}ggplot(data=DATA,aes(x=Year,y=Value,colour=Population))+\end{verbatim} We specify that we want a line graph, and title the plot. \begin{verbatim}geom_line()+gggtitle("This is my plot")\end{verbatim} -We title the y-axis \emph{Y} and the x-axis {X}. We also suppress the legend. -\begin{verbatim}ylab("Pov. rates")+xlab("Time")+guides(fill=FALSE)+\end{verbatim} +We title the y-axis \textbf{Y} and the x-axis \textbf{X}. We also suppress the legend. +\begin{verbatim}ylab("Y")+xlab("X")+guides(fill=FALSE)+\end{verbatim} We control the y-axis and create ticks on the numbers 10, 12 and 14 of the variable \emph{Value}. \begin{verbatim}scale_y_continuous(breaks=c(10,12,14))+ \end{verbatim} We control the tick labels on the x-axis. We angle the tick labels 45 degrees @@ -312,21 +312,9 @@ library(Hmisc)\end{verbatim} \end{itemize} \end{frame} -\begin{frame} -\frametitle{Xtable} -\begin{block}{Exporting using Xtable} -I generally prefer Xtable to Hmisc because -\begin{enumerate} -\item xtable can wrap tables from almost all objects and classes -\item You can modify the LaTeX output a great deal in xtable -\item Most importantly, xtable can export tables without a float -\end{enumerate} -More on the float environment later. -\end{block} -\end{frame} - \begin{frame}[fragile] -\frametitle{List of base tables} +\frametitle{Xtable} +{\small List of base tables} \begin{columns}[T] \begin{column}{.5\textwidth} \begin{block}{R function} @@ -355,9 +343,9 @@ More on the float environment later. \end{frame} \begin{frame}[fragile,shrink] -\frametitle{Xtable imput} +\frametitle{Xtable input} \begin{block}{} -Take nearly any R object of class dataframe, matrix, array, aov, lm...\\ +Take an R object of class dataframe, matrix, array, aov, lm...\\ and then enter \verb|xtable(x)| to provide LaTeX output. You are given a series of options for the output. \end{block} \begin{columns}[T] @@ -372,7 +360,7 @@ and then enter \verb|xtable(x)| to provide LaTeX output. You are given a series \begin{itemize} \item Captions \item Alignment of columns -\item and more +\item others \end{itemize} \end{column} \end{columns} @@ -419,7 +407,8 @@ table \begin{frame}[fragile] \frametitle{Xtable example part 2} -Now lets wrap our xtab() table within xtable. +\small +Now lets wrap our xtab() table within xtable. Again this looks very ugly. We have forgotten to change some options in the chunk code. \begin{verbatim} table2<- xtable(table,digits=1,align="l|rrrrrrrrrrrr") @@ -432,7 +421,8 @@ table2 \begin{frame}[fragile] \frametitle{Example part 3} -We have to modify our R chunk code for LaTeX to properly read xtable +\small +We have to modify our R chunk code for LaTeX to properly read xtable. The table looks right now, except that it is far too large for the frame \begin{verbatim} <> = table2<- @@ -446,7 +436,7 @@ table2 \begin{frame}[fragile] \frametitle{Example part 4} -Now you see our Overfull Hbox problem. First we wrap the xtable within print, specify floating=FALSE and resize the table +This shows our Overfull Hbox problem. To remedy this we wrap the xtable within print, specify floating=FALSE and resize the table \begin{verbatim} \resizebox{\linewidth}{!}{% <> = @@ -610,7 +600,7 @@ Select the header, another row and our alternating rows \begin{verbatim} add.to.row=list(pos=c(list(-1,8),pos), \end{verbatim} -Now lets select colors for these select rows +Now lets select colors for our header, another row and alternating rows \begin{verbatim} command=c("\\rowcolor[rgb]{1,.8,.8}", "\\rowcolor[rgb]{.8,1,0}", @@ -620,11 +610,199 @@ Now we are finished. \end{frame} \begin{frame}[fragile] -\frametitle{A few things on Hmisc} -The Hmisc equivalent of the \verb|xtable()| wrapper is the \verb|latex()| function. To my knowledge, \verb|latex()| will always float the output. So in cases of Overfull Hbox, the table cannot be resized to fit the page.\\[\baselineskip] -If you do not run into a Overfull Hbox, there are cool features in Hmisc not available in xtable, mainly its summarize.formula functions which will only work with Hmisc's latex wrapper +\frametitle{Hmisc} +The Hmisc equivalent of the \verb|xtable()| wrapper is the \verb|latex()| function. It operates in a similar manner to xtable. There are many advanced features in Hmisc that are unavailable to xtable such as multi-line headers, very simple cell selection plus all the functionality of xtable. Hmisc output generally looks cleaner than xtable output. +With our last example table: \verb|tab2|, we can write a basic latex table with Hmisc using the following code. +\begin{verbatim} +latex(tab2, file= '') +\end{verbatim} +\verb|tab2| is the object we want wrapped, and \verb|file= ''| stops Hmisc from creating a separate output postcript file. In other words, it means we will get standard latex output. +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc and Floating} +\small +Like with Xtable, we may run into scenarios where we have Overfull Hbox. In that case we can resize our R table only if our table is non-floating. it In order to specify the output of \verb|latex()| to be a non-floating object, we write: +\begin{verbatim} +latex(...,table.env=FALSE,center=FALSE) +\end{verbatim} +So instead of your last 3 lines of code looking like +\begin{verbatim} +\end{tabular} +\end{center} +\end{table} +\end{verbatim} +You are simply left with +\begin{verbatim} +\end{tabular} +\end{verbatim} +Now we can squeeze in a resize for this tabular environment, then center and table it later if we want. +Like with xtable, these two options are necessary if you need to tinker or resize the table. \end{frame} +\begin{frame} +\frametitle{Hmisc (latex) inputs: Useful options} +\small +\begin{columns}[T] +\begin{column}{.5\textwidth} +\begin{itemize} +\item file: \emph{See slides above} +\item table.env: \emph{See slides above} +\item center: \emph{See slides above} +\item size: \emph{Same as xtable} +\item vbar: \emph{Vertical line divisions} +\item rowname: \emph{Supress row names} +\end{itemize} +\end{column} +\begin{column}{.5\textwidth} +\begin{itemize} +\item extracolheads: \emph{Add sub-headers} +\item cellTexCmds \emph{Format table cells} +\item booktabs: \emph{Different table style} +\item ctable: \emph{Different table style} +\end{itemize} +\end{column} +\end{columns} +\end{frame} + +\begin{frame} +\frametitle{Hmisc (latex) inputs: Group commands} +\small +\begin{columns}[T] +\begin{column}{.5\textwidth} +\begin{block}{Column Groups} +\begin{itemize} +\item cgroup: \emph{Name your column groups} +\item n.cgroup: \emph{Select your column groups} +\item cgroupTexCmd: \emph{Format your column groups} +\item cgroup.just: \emph{Align your column groups} +\end{itemize} +\end{block} +\end{column} +\begin{column}{.5\textwidth} +\begin{block}{Row Groups} +\begin{itemize} +\item rgroup: \emph{Name your row groups} +\item n.rgroup: \emph{Select your row groups} +\item rgroupTexCmd: \emph{Format your row groups} +\item rowlabel: \emph{Simple header for row names} +\end{itemize} +\end{block} +\end{column} +\end{columns} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example part 1} +\small +Lets start with some subsetted data. Here are the first couple rows. +<>= +tab4<-subset(data2,(data2$Geography=="Ontario"|data2$Geography=="Quebec")& + (data2$Statistic=="Percentage of persons in low income"|data2$Statistic=="Number of persons in low income (x 1,000)")& + !data2$Line=="Market basket measure, 2011 base"& + data2$Population=="All persons"& + data2$Year>=2005) +row.names(tab4)<-NULL +head(tab4[1:3]) +head(tab4[4:6]) +@ +\end{frame} + +\begin{frame}[fragile,shrink] +\frametitle{Hmisc example part 2} +\small +The data is in long format so we will call \emph{cast} from the \emph{reshape} package in order to display the data how we want +<>= +tab5<-cast(tab4,Geography+Year~Line+Statistic,value="Value") +colnames(tab5)[3:6]<-c("LICO Persons in low income","LICO Pov. rate","LIM Persons in low income","LIM Pov. rate") +row.names(tab5)<-NULL +tab5[1:4] +tab5[4:6] +@ +\end{frame} + +\begin{frame} +\frametitle{Hmisc example part 3} +\small +For the sake of comparison, lets first create the table in Xtable +\begin{table} +\resizebox{\linewidth}{!}{% +<>= +print(xtable(tab5,align="cc|c||cccc",size="small",digits=1),hline.after=c(-1,0,7,nrow(tab5)),floating=FALSE,include.rownames=FALSE) +@ +} +\caption{Using Xtable} +\end{table} +This looks adequate, but lets see if Hmisc can do better... +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example part 4} +\small +\begin{table} +\resizebox{\linewidth}{!}{% +<>= +tab6<-cast(tab4,Geography+Year~Line+Statistic,value="Value") +tab6<-tab6[,-1] #Remove Geography +colnames(tab6)<-c("Year","Number of persons in low income","Poverty rate","Number of persons in low income","Poverty rate") +latex(tab6,file='',extracolheads=c('','(x 1,000)','\\%','(x 1,000)','\\%'), + cgroup=c('','LICO','LIM'),n.cgroup=c(1,2,2), + rgroup=c('Ontario','Quebec'),n.rgroup=c(7,7), + table.env=FALSE,center='none', + rowlabel='',col.just=c('c','c','c','c','c'), + size='tiny') +@ +} +\caption{Using Hmisc} +\end{table} +This looks a bit nicer I think. Lets go over the code in detail +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example: code} +\small +First, lets cast the data, drop \emph{Geography} and rename headers. +\begin{verbatim} +tab6<-cast(tab4,Geography+Year~Line+Statistic, + value="Value") +tab6<-tab6[,-1] +colnames(tab6)<- +c("Year","Number of persons in low income", + "Poverty rate","Number of persons in low income", + "Poverty rate") +\end{verbatim} +Now lets wrap our \emph{tab6} in Hmisc's latex function and avoid any unecessary file creation. Lets also set a font size. +\begin{verbatim} +latex(tab6,file='',size ='tiny', +\end{verbatim} +Add extra headers beneath our new column names. +\begin{verbatim} +extracolheads=c('','(x 1,000)','\\%', +'(x 1,000)','\\%'), +\end{verbatim} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example: code cont...} +\small +Now lets look at multi-line headers. We want the first 7 rows in one group and the next 7 in another. Then name the respective groups. We want the first row, then the next 2 and the next 2 in groups so name those as well +\begin{verbatim} +n.rgroup=c(7,7),rgroup=c('Ontario','Quebec'), +n.cgroup=c(2,2),cgroup=c('','LICO','LIM'), +\end{verbatim} +Remove any header for the rownames and center all the columns +\begin{verbatim} +rowlabel='',col.just=c('c','c','c','c','c'), +\end{verbatim} +Finally, and most importantly, remove the float (ie. remove \verb|\begin{table} \begin{center}| and the ends as well) so we can resize it later. +\begin{verbatim} +table.env=FALSE,center='none') +\end{verbatim} +\end{frame} + + + + \section{Sweave} \begin{frame} \frametitle{Section 3} diff --git a/Guide.log b/Guide.log index fc4d387..647579a 100644 --- a/Guide.log +++ b/Guide.log @@ -1,4 +1,4 @@ -This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012) (format=pdflatex 2012.6.30) 8 JAN 2014 10:22 +This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012) (format=pdflatex 2012.6.30) 9 JAN 2014 00:09 entering extended mode restricted \write18 enabled. %&-line parsing enabled. @@ -1187,7 +1187,10 @@ Package pdftex.def Info: figure/unnamed-chunk-4.pdf used on input line 4. \openout4 = `Guide.vrb'. -(./Guide.vrb) +(./Guide.vrb +LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <8> not available +(Font) Font shape `OT1/phv/b/n' tried instead on input line 7. +) Overfull \vbox (2.39052pt too high) detected at line 268 [] @@ -1212,18 +1215,16 @@ Overfull \vbox (2.39052pt too high) detected at line 268 (./Guide.vrb) [19 -] -[20 - ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [21 + +(./Guide.vrb) [20 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [22 + (./Guide.vrb) [21 ] \openout4 = `Guide.vrb'. @@ -1231,7 +1232,7 @@ Overfull \vbox (2.39052pt too high) detected at line 268 (./Guide.vrb LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <10> not available (Font) Font shape `OT1/phv/b/n' tried instead on input line 4. -) [23 +) [22 ] \openout4 = `Guide.vrb'. @@ -1239,13 +1240,13 @@ LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <10> not available (./Guide.vrb LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <10.95> not available (Font) Font shape `OT1/phv/b/n' tried instead on input line 2. -) -[24 +) [23 ] \openout4 = `Guide.vrb'. - (./Guide.vrb + +(./Guide.vrb Overfull \hbox (156.01683pt too wide) in paragraph at lines 7--7 []\OT1/pcr/m/n/10.95 table<-with(subset(data2,data2$Year>=2000&data2$Geography= ="Canada"& @@ -1398,120 +1399,109 @@ Overfull \hbox (77.17693pt too wide) in paragraph at lines 35--35 ) Class beamer Warning: Frame text is shrunk by a factor of 52.53754 percent inst -ead of 0 percent on input line 447. +ead of 0 percent on input line 435. -[25 +[24 ] \openout4 = `Guide.vrb'. (./Guide.vrb -Overfull \hbox (4.90701pt too wide) in paragraph at lines 6--6 -[]\OT1/pcr/m/n/10.95 xtable(table,digits=1,align="l|rrrrrrrrrrrr")[] +Overfull \hbox (75.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## % latex table generated in R 3.0.1 by xtable 1.7-1 package +[] [] -Overfull \hbox (110.02689pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## % latex table generated in R 3.0.1 by xtable 1.7-1 pack -age[] +Overfull \hbox (249.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## & 2000 & 2001 & 2002 & 2003 & 2004 & 2005 & 2006 & 2007 & + 2008 & 2009 & 2010 & 2011 \\[] [] -Overfull \hbox (300.55666pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## & 2000 & 2001 & 2002 & 2003 & 2004 & 2005 & 2006 & 200 -7 & 2008 & 2009 & 2010 & 2011 \\[] +Overfull \hbox (261.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Females & 13.6 & 12.1 & 12.4 & 12.2 & 11.9 & 11.1 & 10.7 & + 9.3 & 9.8 & 9.5 & 9.3 & 8.9 \\[] [] -Overfull \hbox (313.69664pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Females & 13.6 & 12.1 & 12.4 & 12.2 & 11.9 & 11.1 & 10. -7 & 9.3 & 9.8 & 9.5 & 9.3 & 8.9 \\[] +Overfull \hbox (261.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Males & 11.4 & 10.3 & 10.7 & 11.0 & 10.8 & 10.5 & 10.0 & + 9.0 & 8.9 & 9.5 & 8.7 & 8.7 \\[] [] -Overfull \hbox (313.69664pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Males & 11.4 & 10.3 & 10.7 & 11.0 & 10.8 & 10.5 & 10. -0 & 9.0 & 8.9 & 9.5 & 8.7 & 8.7 \\[] +Overfull \hbox (363.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Persons under 18 years & 13.9 & 12.2 & 12.4 & 12.7 & 13. +0 & 11.7 & 11.1 & 9.5 & 9.0 & 9.4 & 8.2 & 8.5 \\[] [] -Overfull \hbox (425.3865pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Persons under 18 years & 13.9 & 12.2 & 12.4 & 12.7 & -13.0 & 11.7 & 11.1 & 9.5 & 9.0 & 9.4 & 8.2 & 8.5 \\[] +Overfull \hbox (381.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Persons 18 to 64 years & 12.9 & 11.7 & 12.0 & 12.2 & 11. +9 & 11.4 & 11.1 & 9.9 & 10.1 & 10.4 & 10.1 & 9.7 \\[] [] -Overfull \hbox (445.09648pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Persons 18 to 64 years & 12.9 & 11.7 & 12.0 & 12.2 & -11.9 & 11.4 & 11.1 & 9.9 & 10.1 & 10.4 & 10.1 & 9.7 \\[] +Overfull \hbox (339.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Persons 65 years and over & 7.6 & 6.7 & 7.6 & 6.8 & 5.6 +& 6.2 & 5.3 & 4.8 & 5.8 & 5.1 & 5.3 & 5.2 \\[] [] -Overfull \hbox (399.10654pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Persons 65 years and over & 7.6 & 6.7 & 7.6 & 6.8 & 5 -.6 & 6.2 & 5.3 & 4.8 & 5.8 & 5.1 & 5.3 & 5.2 \\[] +Overfull \hbox (357.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Persons in economic families & 9.3 & 8.1 & 8.6 & 8.7 & 8 +.2 & 7.5 & 7.1 & 6.0 & 6.2 & 6.5 & 5.9 & 5.5 \\[] [] -Overfull \hbox (418.81651pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Persons in economic families & 9.3 & 8.1 & 8.6 & 8.7 -& 8.2 & 7.5 & 7.1 & 6.0 & 6.2 & 6.5 & 5.9 & 5.5 \\[] +Overfull \hbox (447.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Child in single mother families & 40.1 & 37.4 & 43.0 & 4 +1.4 & 40.4 & 32.9 & 31.2 & 26.7 & 23.3 & 21.5 & 21.8 & 23.0 \\[] [] -Overfull \hbox (517.3664pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Child in single mother families & 40.1 & 37.4 & 43.0 -& 41.4 & 40.4 & 32.9 & 31.2 & 26.7 & 23.3 & 21.5 & 21.8 & 23.0 \\[] +Overfull \hbox (357.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Child in two-parent families & 9.5 & 8.3 & 7.4 & 7.9 & 8 +.4 & 7.8 & 7.5 & 6.5 & 6.4 & 7.3 & 5.7 & 5.9 \\[] [] -Overfull \hbox (418.81651pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Child in two-parent families & 9.5 & 8.3 & 7.4 & 7.9 -& 8.4 & 7.8 & 7.5 & 6.5 & 6.4 & 7.3 & 5.7 & 5.9 \\[] +Overfull \hbox (393.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## Unattached individuals & 32.9 & 30.8 & 29.5 & 29.7 & 30. +1 & 30.5 & 29.4 & 27.6 & 27.3 & 26.9 & 26.9 & 27.7 \\[] [] -Overfull \hbox (458.23647pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## Unattached individuals & 32.9 & 30.8 & 29.5 & 29.7 & -30.1 & 30.5 & 29.4 & 27.6 & 27.3 & 26.9 & 26.9 & 27.7 \\[] - [] - - -Overfull \hbox (353.1166pt too wide) in paragraph at lines 31--31 -[]\OT1/pcr/m/n/10.95 ## All persons & 12.5 & 11.2 & 11.6 & 11.6 & 11.4 & 10.8 - & 10.3 & 9.1 & 9.3 & 9.5 & 9.0 & 8.8 \\[] +Overfull \hbox (297.25737pt too wide) in paragraph at lines 32--32 +[]\OT1/pcr/m/n/10 ## All persons & 12.5 & 11.2 & 11.6 & 11.6 & 11.4 & 10.8 & +10.3 & 9.1 & 9.3 & 9.5 & 9.0 & 8.8 \\[] [] ) -Overfull \vbox (142.49896pt too high) detected at line 484 +Overfull \vbox (127.36449pt too high) detected at line 473 [] -[26 +[25 ] \openout4 = `Guide.vrb'. (./Guide.vrb -Overfull \hbox (11.477pt too wide) in paragraph at lines 8--8 -[]\OT1/pcr/m/n/10.95 <> =[] - [] - - -Overfull \hbox (4.90701pt too wide) in paragraph at lines 8--8 -[]\OT1/pcr/m/n/10.95 xtable(table,digits=1,align="l|rrrrrrrrrrrr")[] - [] - +LaTeX Font Info: Font shape `OT1/phv/m/it' in size <10> not available +(Font) Font shape `OT1/phv/m/sl' tried instead on input line 14. +LaTeX Font Info: Font shape `OT1/phv/m/it' in size <7> not available +(Font) Font shape `OT1/phv/m/sl' tried instead on input line 14. -Overfull \hbox (302.98358pt too wide) in paragraph at lines 13--29 +Overfull \hbox (265.04263pt too wide) in paragraph at lines 14--30 [] [] ) -Overfull \vbox (58.63449pt too high) detected at line 518 +Overfull \vbox (41.83455pt too high) detected at line 508 [] -[27 +[26 ] \openout4 = `Guide.vrb'. @@ -1522,32 +1512,27 @@ Overfull \hbox (4.90701pt too wide) in paragraph at lines 9--9 1/pcr/m/n/10.95 asis\TS1/pcr/m/n/10.95 '\OT1/pcr/m/n/10.95 >> =[] [] -) [28 +) [27 -] [29 +] [28 ] \openout4 = `Guide.vrb'. (./Guide.vrb) -Overfull \vbox (4.15788pt too high) detected at line 590 +Overfull \vbox (4.15788pt too high) detected at line 580 [] -[30 +[29 ] \openout4 = `Guide.vrb'. - (./Guide.vrb -LaTeX Font Info: Font shape `OT1/phv/m/it' in size <10> not available -(Font) Font shape `OT1/phv/m/sl' tried instead on input line 10. -LaTeX Font Info: Font shape `OT1/phv/m/it' in size <7> not available -(Font) Font shape `OT1/phv/m/sl' tried instead on input line 10. -) -Overfull \vbox (4.77444pt too high) detected at line 635 + (./Guide.vrb) +Overfull \vbox (4.77444pt too high) detected at line 625 [] -[31 +[30 ] \openout4 = `Guide.vrb'. @@ -1581,10 +1566,15 @@ Overfull \hbox (13.16818pt too wide) in paragraph at lines 56--57 [] ) -Overfull \vbox (12.84763pt too high) detected at line 698 +Overfull \vbox (12.84763pt too high) detected at line 688 [] -[32 +[31 + +] +\openout4 = `Guide.vrb'. + + (./Guide.vrb) [32 ] \openout4 = `Guide.vrb'. @@ -1599,40 +1589,85 @@ Overfull \vbox (12.84763pt too high) detected at line 698 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [35 + (./Guide.vrb) +[35 ] [36 +] [37 + +] +\openout4 = `Guide.vrb'. + + (./Guide.vrb) [38 + +] +\openout4 = `Guide.vrb'. + + (./Guide.vrb) + +Class beamer Warning: Frame text is shrunk by a factor of 17.64221 percent inst +ead of 0 percent on input line 889. + +[39 + +] [40 + ] -Overfull \vbox (2.771pt too high) detected at line 773 +\openout4 = `Guide.vrb'. + + (./Guide.vrb +LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <6> not available +(Font) Font shape `OT1/phv/b/n' tried instead on input line 37. +) [41 + +] +\openout4 = `Guide.vrb'. + + (./Guide.vrb +Overfull \hbox (15.25737pt too wide) in paragraph at lines 12--12 +[] \OT1/pcr/m/n/10 "Poverty rate","Number of persons in low income",[] [] -[37 +) [42 ] \openout4 = `Guide.vrb'. - (./Guide.vrb + (./Guide.vrb) [43 + +] [44 + +] +Overfull \vbox (2.771pt too high) detected at line 1035 + [] + +[45 + +] +\openout4 = `Guide.vrb'. + + (./Guide.vrb File: GuidePic1.pdf Graphic file (type pdf) Package pdftex.def Info: GuidePic1.pdf used on input line 16. (pdftex.def) Requested size: 145.3713pt x 120.27203pt. -) [38 +) [46 <./GuidePic1.pdf>] \openout4 = `Guide.vrb'. - (./Guide.vrb) [39 + (./Guide.vrb) [47 ] \openout4 = `Guide.vrb'. (./Guide.vrb) -Overfull \vbox (8.601pt too high) detected at line 836 +Overfull \vbox (8.601pt too high) detected at line 1098 [] -[40 +[48 ] \openout4 = `Guide.vrb'. @@ -1643,66 +1678,66 @@ Overfull \hbox (4.90701pt too wide) in paragraph at lines 3--3 T1/pcr/m/n/10.95 tiny\TS1/pcr/m/n/10.95 '\OT1/pcr/m/n/10.95 >>=[] [] -) [41 +) [49 -] [42 +] [50 -] [43 +] [51 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [44 + (./Guide.vrb) [52 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [45 + (./Guide.vrb) [53 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [46 + (./Guide.vrb) [54 ] \openout4 = `Guide.vrb'. -(./Guide.vrb) [47 +(./Guide.vrb) [55 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [48 + (./Guide.vrb) [56 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [49 + (./Guide.vrb) [57 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [50 + (./Guide.vrb) [58 ] -[51 +[59 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [52 + (./Guide.vrb) [60 -] [53 +] [61 -] [54 +] [62 -] [55 +] [63 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [56 + (./Guide.vrb) [64 ] \openout4 = `Guide.vrb'. @@ -1755,45 +1790,42 @@ pcr/m/n/10.95 ([][]legend.position[] []=[] []"none"[][],[] []axis.text.x[] []=[ 45[][]))[] []+[][] [] -
-File: figure/unnamed-chunk-11.pdf Graphic file (type pdf) +
+File: figure/unnamed-chunk-15.pdf Graphic file (type pdf) - -Package pdftex.def Info: figure/unnamed-chunk-11.pdf used on input line 14. + +Package pdftex.def Info: figure/unnamed-chunk-15.pdf used on input line 14. (pdftex.def) Requested size: 290.74263pt x 290.74553pt. ) -Overfull \vbox (196.51172pt too high) detected at line 1032 +Overfull \vbox (196.51172pt too high) detected at line 1294 [] -[57 +[65 - <./figure/unnamed-chunk-11.pdf>] -
-File: figure/unnamed-chunk-12.pdf Graphic file (type pdf) + <./figure/unnamed-chunk-15.pdf>] +
+File: figure/unnamed-chunk-16.pdf Graphic file (type pdf) - -Package pdftex.def Info: figure/unnamed-chunk-12.pdf used on input line 1043. + +Package pdftex.def Info: figure/unnamed-chunk-16.pdf used on input line 1305. (pdftex.def) Requested size: 290.74263pt x 124.60522pt. - [58 + [66 - <./figure/unnamed-chunk-12.pdf>] + <./figure/unnamed-chunk-16.pdf>] \openout4 = `Guide.vrb'. -(./Guide.vrb -LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <8> not available -(Font) Font shape `OT1/phv/b/n' tried instead on input line 4. -) [59 +(./Guide.vrb) [67 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [60 + (./Guide.vrb) [68 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [61 + (./Guide.vrb) [69 ] \openout4 = `Guide.vrb'. @@ -1801,15 +1833,15 @@ LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <8> not available (./Guide.vrb LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <9> not available (Font) Font shape `OT1/phv/b/n' tried instead on input line 5. -) [62 +) [70 ] -[63 +[71 ] \openout4 = `Guide.vrb'. - (./Guide.vrb) [64 + (./Guide.vrb) [72 ] \tf@nav=\write6 @@ -1821,37 +1853,38 @@ LaTeX Font Info: Font shape `OT1/phv/bx/n' in size <9> not available \tf@snm=\write8 \openout8 = `Guide.snm'. -Package atveryend Info: Empty hook `BeforeClearDocument' on input line 1107. -Package atveryend Info: Empty hook `AfterLastShipout' on input line 1107. +Package atveryend Info: Empty hook `BeforeClearDocument' on input line 1369. +Package atveryend Info: Empty hook `AfterLastShipout' on input line 1369. (./Guide.aux) -Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 1107. -Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 1107. +Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 1369. +Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 1369. Package rerunfilecheck Info: File `Guide.out' has not changed. (rerunfilecheck) Checksum: 5400A071E3101DA539AAFC40437BC1F8;175. -Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 1107. +Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 1369. ) Here is how much of TeX's memory you used: - 18200 strings out of 493488 - 336104 string characters out of 3141326 - 433640 words of memory out of 3000000 - 20795 multiletter control sequences out of 15000+200000 - 48991 words of font info for 102 fonts, out of 3000000 for 9000 + 18251 strings out of 493488 + 336607 string characters out of 3141326 + 433638 words of memory out of 3000000 + 20816 multiletter control sequences out of 15000+200000 + 51432 words of font info for 107 fonts, out of 3000000 for 9000 957 hyphenation exceptions out of 8191 49i,16n,60p,466b,1454s stack positions out of 5000i,500n,10000p,200000b,50000s {/usr/local/texlive/2012/texmf-dist/fonts/enc/dvips/base/8r.enc} -Output written on Guide.pdf (64 pages, 248429 bytes). +exlive/2012/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi6.pfb> +Output written on Guide.pdf (72 pages, 269962 bytes). PDF statistics: - 926 PDF objects out of 1000 (max. 8388607) - 812 compressed objects within 9 object streams - 133 named destinations out of 1000 (max. 500000) + 1022 PDF objects out of 1200 (max. 8388607) + 899 compressed objects within 9 object streams + 149 named destinations out of 1000 (max. 500000) 157 words of extra memory for PDF output out of 10000 (max. 10000000) diff --git a/Guide.nav b/Guide.nav index fb3e4ee..31c058e 100644 --- a/Guide.nav +++ b/Guide.nav @@ -75,68 +75,84 @@ \headcommand {\beamer@framepages {34}{34}} \headcommand {\slideentry {2}{0}{35}{35/35}{}{0}} \headcommand {\beamer@framepages {35}{35}} -\headcommand {\sectionentry {3}{Sweave}{36}{Sweave}{0}} -\headcommand {\beamer@sectionpages {17}{35}} -\headcommand {\beamer@subsectionpages {17}{35}} -\headcommand {\slideentry {3}{0}{36}{36/36}{}{0}} +\headcommand {\slideentry {2}{0}{36}{36/36}{}{0}} \headcommand {\beamer@framepages {36}{36}} -\headcommand {\slideentry {3}{0}{37}{37/37}{}{0}} +\headcommand {\slideentry {2}{0}{37}{37/37}{}{0}} \headcommand {\beamer@framepages {37}{37}} -\headcommand {\slideentry {3}{0}{38}{38/38}{}{0}} +\headcommand {\slideentry {2}{0}{38}{38/38}{}{0}} \headcommand {\beamer@framepages {38}{38}} -\headcommand {\slideentry {3}{0}{39}{39/39}{}{0}} +\headcommand {\slideentry {2}{0}{39}{39/39}{}{0}} \headcommand {\beamer@framepages {39}{39}} -\headcommand {\slideentry {3}{0}{40}{40/40}{}{0}} +\headcommand {\slideentry {2}{0}{40}{40/40}{}{0}} \headcommand {\beamer@framepages {40}{40}} -\headcommand {\slideentry {3}{0}{41}{41/41}{}{0}} +\headcommand {\slideentry {2}{0}{41}{41/41}{}{0}} \headcommand {\beamer@framepages {41}{41}} -\headcommand {\slideentry {3}{0}{42}{42/42}{}{0}} +\headcommand {\slideentry {2}{0}{42}{42/42}{}{0}} \headcommand {\beamer@framepages {42}{42}} -\headcommand {\sectionentry {4}{Beamer}{43}{Beamer}{0}} -\headcommand {\beamer@sectionpages {36}{42}} -\headcommand {\beamer@subsectionpages {36}{42}} -\headcommand {\slideentry {4}{0}{43}{43/43}{}{0}} +\headcommand {\slideentry {2}{0}{43}{43/43}{}{0}} \headcommand {\beamer@framepages {43}{43}} -\headcommand {\slideentry {4}{0}{44}{44/44}{}{0}} +\headcommand {\sectionentry {3}{Sweave}{44}{Sweave}{0}} +\headcommand {\beamer@sectionpages {17}{43}} +\headcommand {\beamer@subsectionpages {17}{43}} +\headcommand {\slideentry {3}{0}{44}{44/44}{}{0}} \headcommand {\beamer@framepages {44}{44}} -\headcommand {\slideentry {4}{0}{45}{45/45}{}{0}} +\headcommand {\slideentry {3}{0}{45}{45/45}{}{0}} \headcommand {\beamer@framepages {45}{45}} -\headcommand {\slideentry {4}{0}{46}{46/46}{}{0}} +\headcommand {\slideentry {3}{0}{46}{46/46}{}{0}} \headcommand {\beamer@framepages {46}{46}} -\headcommand {\slideentry {4}{0}{47}{47/47}{}{0}} +\headcommand {\slideentry {3}{0}{47}{47/47}{}{0}} \headcommand {\beamer@framepages {47}{47}} -\headcommand {\slideentry {4}{0}{48}{48/48}{}{0}} +\headcommand {\slideentry {3}{0}{48}{48/48}{}{0}} \headcommand {\beamer@framepages {48}{48}} -\headcommand {\slideentry {4}{0}{49}{49/49}{}{0}} +\headcommand {\slideentry {3}{0}{49}{49/49}{}{0}} \headcommand {\beamer@framepages {49}{49}} -\headcommand {\slideentry {4}{0}{50}{50/50}{}{0}} +\headcommand {\slideentry {3}{0}{50}{50/50}{}{0}} \headcommand {\beamer@framepages {50}{50}} +\headcommand {\sectionentry {4}{Beamer}{51}{Beamer}{0}} +\headcommand {\beamer@sectionpages {44}{50}} +\headcommand {\beamer@subsectionpages {44}{50}} \headcommand {\slideentry {4}{0}{51}{51/51}{}{0}} \headcommand {\beamer@framepages {51}{51}} \headcommand {\slideentry {4}{0}{52}{52/52}{}{0}} \headcommand {\beamer@framepages {52}{52}} -\headcommand {\slideentry {4}{0}{53}{53/55}{}{0}} -\headcommand {\beamer@framepages {53}{55}} -\headcommand {\slideentry {4}{0}{54}{56/56}{}{0}} +\headcommand {\slideentry {4}{0}{53}{53/53}{}{0}} +\headcommand {\beamer@framepages {53}{53}} +\headcommand {\slideentry {4}{0}{54}{54/54}{}{0}} +\headcommand {\beamer@framepages {54}{54}} +\headcommand {\slideentry {4}{0}{55}{55/55}{}{0}} +\headcommand {\beamer@framepages {55}{55}} +\headcommand {\slideentry {4}{0}{56}{56/56}{}{0}} \headcommand {\beamer@framepages {56}{56}} -\headcommand {\slideentry {4}{0}{55}{57/57}{}{0}} +\headcommand {\slideentry {4}{0}{57}{57/57}{}{0}} \headcommand {\beamer@framepages {57}{57}} -\headcommand {\slideentry {4}{0}{56}{58/58}{}{0}} +\headcommand {\slideentry {4}{0}{58}{58/58}{}{0}} \headcommand {\beamer@framepages {58}{58}} -\headcommand {\slideentry {4}{0}{57}{59/59}{}{0}} +\headcommand {\slideentry {4}{0}{59}{59/59}{}{0}} \headcommand {\beamer@framepages {59}{59}} -\headcommand {\slideentry {4}{0}{58}{60/60}{}{0}} +\headcommand {\slideentry {4}{0}{60}{60/60}{}{0}} \headcommand {\beamer@framepages {60}{60}} -\headcommand {\slideentry {4}{0}{59}{61/61}{}{0}} -\headcommand {\beamer@framepages {61}{61}} -\headcommand {\slideentry {4}{0}{60}{62/62}{}{0}} -\headcommand {\beamer@framepages {62}{62}} -\headcommand {\slideentry {4}{0}{61}{63/63}{}{0}} -\headcommand {\beamer@framepages {63}{63}} +\headcommand {\slideentry {4}{0}{61}{61/63}{}{0}} +\headcommand {\beamer@framepages {61}{63}} \headcommand {\slideentry {4}{0}{62}{64/64}{}{0}} \headcommand {\beamer@framepages {64}{64}} -\headcommand {\beamer@partpages {1}{64}} -\headcommand {\beamer@subsectionpages {43}{64}} -\headcommand {\beamer@sectionpages {43}{64}} -\headcommand {\beamer@documentpages {64}} -\headcommand {\def \inserttotalframenumber {61}} +\headcommand {\slideentry {4}{0}{63}{65/65}{}{0}} +\headcommand {\beamer@framepages {65}{65}} +\headcommand {\slideentry {4}{0}{64}{66/66}{}{0}} +\headcommand {\beamer@framepages {66}{66}} +\headcommand {\slideentry {4}{0}{65}{67/67}{}{0}} +\headcommand {\beamer@framepages {67}{67}} +\headcommand {\slideentry {4}{0}{66}{68/68}{}{0}} +\headcommand {\beamer@framepages {68}{68}} +\headcommand {\slideentry {4}{0}{67}{69/69}{}{0}} +\headcommand {\beamer@framepages {69}{69}} +\headcommand {\slideentry {4}{0}{68}{70/70}{}{0}} +\headcommand {\beamer@framepages {70}{70}} +\headcommand {\slideentry {4}{0}{69}{71/71}{}{0}} +\headcommand {\beamer@framepages {71}{71}} +\headcommand {\slideentry {4}{0}{70}{72/72}{}{0}} +\headcommand {\beamer@framepages {72}{72}} +\headcommand {\beamer@partpages {1}{72}} +\headcommand {\beamer@subsectionpages {51}{72}} +\headcommand {\beamer@sectionpages {51}{72}} +\headcommand {\beamer@documentpages {72}} +\headcommand {\def \inserttotalframenumber {69}} diff --git a/Guide.pdf b/Guide.pdf index b553a6a..2290e2d 100644 Binary files a/Guide.pdf and b/Guide.pdf differ diff --git a/Guide.synctex.gz b/Guide.synctex.gz index 5688285..3f69723 100644 Binary files a/Guide.synctex.gz and b/Guide.synctex.gz differ diff --git a/Guide.tex b/Guide.tex index 21d91de..9a74f63 100644 --- a/Guide.tex +++ b/Guide.tex @@ -256,8 +256,8 @@ \section{GGPLOT2} \begin{verbatim}ggplot(data=DATA,aes(x=Year,y=Value,colour=Population))+\end{verbatim} We specify that we want a line graph, and title the plot. \begin{verbatim}geom_line()+gggtitle("This is my plot")\end{verbatim} -We title the y-axis \emph{Y} and the x-axis {X}. We also suppress the legend. -\begin{verbatim}ylab("Pov. rates")+xlab("Time")+guides(fill=FALSE)+\end{verbatim} +We title the y-axis \textbf{Y} and the x-axis \textbf{X}. We also suppress the legend. +\begin{verbatim}ylab("Y")+xlab("X")+guides(fill=FALSE)+\end{verbatim} We control the y-axis and create ticks on the numbers 10, 12 and 14 of the variable \emph{Value}. \begin{verbatim}scale_y_continuous(breaks=c(10,12,14))+ \end{verbatim} We control the tick labels on the x-axis. We angle the tick labels 45 degrees @@ -315,21 +315,9 @@ \section{Xtable and Hmisc} \end{itemize} \end{frame} -\begin{frame} -\frametitle{Xtable} -\begin{block}{Exporting using Xtable} -I generally prefer Xtable to Hmisc because -\begin{enumerate} -\item xtable can wrap tables from almost all objects and classes -\item You can modify the LaTeX output a great deal in xtable -\item Most importantly, xtable can export tables without a float -\end{enumerate} -More on the float environment later. -\end{block} -\end{frame} - \begin{frame}[fragile] -\frametitle{List of base tables} +\frametitle{Xtable} +{\small List of base tables} \begin{columns}[T] \begin{column}{.5\textwidth} \begin{block}{R function} @@ -358,9 +346,9 @@ \section{Xtable and Hmisc} \end{frame} \begin{frame}[fragile,shrink] -\frametitle{Xtable imput} +\frametitle{Xtable input} \begin{block}{} -Take nearly any R object of class dataframe, matrix, array, aov, lm...\\ +Take an R object of class dataframe, matrix, array, aov, lm...\\ and then enter \verb|xtable(x)| to provide LaTeX output. You are given a series of options for the output. \end{block} \begin{columns}[T] @@ -375,7 +363,7 @@ \section{Xtable and Hmisc} \begin{itemize} \item Captions \item Alignment of columns -\item and more +\item others \end{itemize} \end{column} \end{columns} @@ -448,7 +436,8 @@ \section{Xtable and Hmisc} \begin{frame}[fragile] \frametitle{Xtable example part 2} -Now lets wrap our xtab() table within xtable. +\small +Now lets wrap our xtab() table within xtable. Again this looks very ugly. We have forgotten to change some options in the chunk code. \begin{verbatim} table2<- xtable(table,digits=1,align="l|rrrrrrrrrrrr") @@ -457,7 +446,7 @@ \section{Xtable and Hmisc} \definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} \begin{verbatim} ## % latex table generated in R 3.0.1 by xtable 1.7-1 package -## % Wed Jan 8 10:22:00 2014 +## % Thu Jan 9 00:09:20 2014 ## \begin{table}[ht] ## \centering ## \begin{tabular}{l|rrrrrrrrrrrr} @@ -485,7 +474,8 @@ \section{Xtable and Hmisc} \begin{frame}[fragile] \frametitle{Example part 3} -We have to modify our R chunk code for LaTeX to properly read xtable +\small +We have to modify our R chunk code for LaTeX to properly read xtable. The table looks right now, except that it is far too large for the frame \begin{verbatim} <> = table2<- @@ -493,7 +483,7 @@ \section{Xtable and Hmisc} @ \end{verbatim} % latex table generated in R 3.0.1 by xtable 1.7-1 package -% Wed Jan 8 10:22:00 2014 +% Thu Jan 9 00:09:21 2014 \begin{table}[ht] \centering \begin{tabular}{l|rrrrrrrrrrrr} @@ -519,7 +509,7 @@ \section{Xtable and Hmisc} \begin{frame}[fragile] \frametitle{Example part 4} -Now you see our Overfull Hbox problem. First we wrap the xtable within print, specify floating=FALSE and resize the table +This shows our Overfull Hbox problem. To remedy this we wrap the xtable within print, specify floating=FALSE and resize the table \begin{verbatim} \resizebox{\linewidth}{!}{% <> = @@ -529,7 +519,7 @@ \section{Xtable and Hmisc} \end{verbatim} \resizebox{\linewidth}{!}{% % latex table generated in R 3.0.1 by xtable 1.7-1 package -% Wed Jan 8 10:22:00 2014 +% Thu Jan 9 00:09:21 2014 \begin{tabular}{l|rrrrrrrrrrrr} \hline & 2000 & 2001 & 2002 & 2003 & 2004 & 2005 & 2006 & 2007 & 2008 & 2009 & 2010 & 2011 \\ @@ -596,7 +586,7 @@ \section{Xtable and Hmisc} \begin{columns}[T] \begin{column}{0.5\textwidth} % latex table generated in R 3.0.1 by xtable 1.7-1 package -% Wed Jan 8 10:22:00 2014 +% Thu Jan 9 00:09:21 2014 \begin{table}[ht] \centering \begin{tabular}{rrrr} @@ -639,7 +629,7 @@ \section{Xtable and Hmisc} \begin{columns}[T] \begin{column}{.5\textwidth} % latex table generated in R 3.0.1 by xtable 1.7-1 package -% Wed Jan 8 10:22:00 2014 +% Thu Jan 9 00:09:21 2014 \begin{table}[ht] \centering {\small @@ -736,7 +726,7 @@ \section{Xtable and Hmisc} \begin{verbatim} add.to.row=list(pos=c(list(-1,8),pos), \end{verbatim} -Now lets select colors for these select rows +Now lets select colors for our header, another row and alternating rows \begin{verbatim} command=c("\\rowcolor[rgb]{1,.8,.8}", "\\rowcolor[rgb]{.8,1,0}", @@ -746,11 +736,283 @@ \section{Xtable and Hmisc} \end{frame} \begin{frame}[fragile] -\frametitle{A few things on Hmisc} -The Hmisc equivalent of the \verb|xtable()| wrapper is the \verb|latex()| function. To my knowledge, \verb|latex()| will always float the output. So in cases of Overfull Hbox, the table cannot be resized to fit the page.\\[\baselineskip] -If you do not run into a Overfull Hbox, there are cool features in Hmisc not available in xtable, mainly its summarize.formula functions which will only work with Hmisc's latex wrapper +\frametitle{Hmisc} +The Hmisc equivalent of the \verb|xtable()| wrapper is the \verb|latex()| function. It operates in a similar manner to xtable. There are many advanced features in Hmisc that are unavailable to xtable such as multi-line headers, very simple cell selection plus all the functionality of xtable. Hmisc output generally looks cleaner than xtable output. +With our last example table: \verb|tab2|, we can write a basic latex table with Hmisc using the following code. +\begin{verbatim} +latex(tab2, file= '') +\end{verbatim} +\verb|tab2| is the object we want wrapped, and \verb|file= ''| stops Hmisc from creating a separate output postcript file. In other words, it means we will get standard latex output. +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc and Floating} +\small +Like with Xtable, we may run into scenarios where we have Overfull Hbox. In that case we can resize our R table only if our table is non-floating. it In order to specify the output of \verb|latex()| to be a non-floating object, we write: +\begin{verbatim} +latex(...,table.env=FALSE,center=FALSE) +\end{verbatim} +So instead of your last 3 lines of code looking like +\begin{verbatim} +\end{tabular} +\end{center} +\end{table} +\end{verbatim} +You are simply left with +\begin{verbatim} +\end{tabular} +\end{verbatim} +Now we can squeeze in a resize for this tabular environment, then center and table it later if we want. +Like with xtable, these two options are necessary if you need to tinker or resize the table. \end{frame} +\begin{frame} +\frametitle{Hmisc (latex) inputs: Useful options} +\small +\begin{columns}[T] +\begin{column}{.5\textwidth} +\begin{itemize} +\item file: \emph{See slides above} +\item table.env: \emph{See slides above} +\item center: \emph{See slides above} +\item size: \emph{Same as xtable} +\item vbar: \emph{Vertical line divisions} +\item rowname: \emph{Supress row names} +\end{itemize} +\end{column} +\begin{column}{.5\textwidth} +\begin{itemize} +\item extracolheads: \emph{Add sub-headers} +\item cellTexCmds \emph{Format table cells} +\item booktabs: \emph{Different table style} +\item ctable: \emph{Different table style} +\end{itemize} +\end{column} +\end{columns} +\end{frame} + +\begin{frame} +\frametitle{Hmisc (latex) inputs: Group commands} +\small +\begin{columns}[T] +\begin{column}{.5\textwidth} +\begin{block}{Column Groups} +\begin{itemize} +\item cgroup: \emph{Name your column groups} +\item n.cgroup: \emph{Select your column groups} +\item cgroupTexCmd: \emph{Format your column groups} +\item cgroup.just: \emph{Align your column groups} +\end{itemize} +\end{block} +\end{column} +\begin{column}{.5\textwidth} +\begin{block}{Row Groups} +\begin{itemize} +\item rgroup: \emph{Name your row groups} +\item n.rgroup: \emph{Select your row groups} +\item rgroupTexCmd: \emph{Format your row groups} +\item rowlabel: \emph{Simple header for row names} +\end{itemize} +\end{block} +\end{column} +\end{columns} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example part 1} +\small +Lets start with some subsetted data. Here are the first couple rows. +\begin{knitrout}\tiny +\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} +\begin{verbatim} +## Year Geography Line +## 1 2005 Quebec Low income cut-offs after tax, 1992 base +## 2 2006 Quebec Low income cut-offs after tax, 1992 base +## 3 2007 Quebec Low income cut-offs after tax, 1992 base +## 4 2008 Quebec Low income cut-offs after tax, 1992 base +## 5 2009 Quebec Low income cut-offs after tax, 1992 base +## 6 2010 Quebec Low income cut-offs after tax, 1992 base +## Statistic Population Value +## 1 Number of persons in low income (x 1,000) All persons 870 +## 2 Number of persons in low income (x 1,000) All persons 828 +## 3 Number of persons in low income (x 1,000) All persons 784 +## 4 Number of persons in low income (x 1,000) All persons 828 +## 5 Number of persons in low income (x 1,000) All persons 686 +## 6 Number of persons in low income (x 1,000) All persons 778 +\end{verbatim} +\end{kframe} +\end{knitrout} + +\end{frame} + +\begin{frame}[fragile,shrink] +\frametitle{Hmisc example part 2} +\small +The data is in long format so we will call \emph{cast} from the \emph{reshape} package in order to display the data how we want +\begin{knitrout}\tiny +\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} +\begin{verbatim} +## Geography Year LICO Persons in low income LICO Pov. rate +## 1 Ontario 2005 1276 10.3 +## 2 Ontario 2006 1283 10.3 +## 3 Ontario 2007 1111 8.8 +## 4 Ontario 2008 1187 9.3 +## 5 Ontario 2009 1306 10.1 +## 6 Ontario 2010 1153 8.8 +## 7 Ontario 2011 1182 9.0 +## 8 Quebec 2005 870 11.7 +## 9 Quebec 2006 828 11.1 +## 10 Quebec 2007 784 10.4 +## 11 Quebec 2008 828 10.9 +## 12 Quebec 2009 686 8.9 +## 13 Quebec 2010 778 10.0 +## 14 Quebec 2011 745 9.5 +## LICO Pov. rate LIM Persons in low income LIM Pov. rate +## 1 10.3 1452 11.7 +## 2 10.3 1418 11.3 +## 3 8.8 1418 11.2 +## 4 9.3 1588 12.4 +## 5 10.1 1681 13.0 +## 6 8.8 1608 12.3 +## 7 9.0 1576 12.0 +## 8 11.7 1048 14.1 +## 9 11.1 1006 13.4 +## 10 10.4 1076 14.3 +## 11 10.9 1172 15.4 +## 12 8.9 1030 13.4 +## 13 10.0 1129 14.5 +## 14 9.5 1095 14.0 +\end{verbatim} +\end{kframe} +\end{knitrout} + +\end{frame} + +\begin{frame} +\frametitle{Hmisc example part 3} +\small +For the sake of comparison, lets first create the table in Xtable +\begin{table} +\resizebox{\linewidth}{!}{% +% latex table generated in R 3.0.1 by xtable 1.7-1 package +% Thu Jan 9 00:09:21 2014 +\begin{tabular}{c|c||cccc} + \hline +Geography & Year & LICO Persons in low income & LICO Pov. rate & LIM Persons in low income & LIM Pov. rate \\ + \hline +Ontario & 2005 & 1276.0 & 10.3 & 1452.0 & 11.7 \\ + Ontario & 2006 & 1283.0 & 10.3 & 1418.0 & 11.3 \\ + Ontario & 2007 & 1111.0 & 8.8 & 1418.0 & 11.2 \\ + Ontario & 2008 & 1187.0 & 9.3 & 1588.0 & 12.4 \\ + Ontario & 2009 & 1306.0 & 10.1 & 1681.0 & 13.0 \\ + Ontario & 2010 & 1153.0 & 8.8 & 1608.0 & 12.3 \\ + Ontario & 2011 & 1182.0 & 9.0 & 1576.0 & 12.0 \\ + \hline +Quebec & 2005 & 870.0 & 11.7 & 1048.0 & 14.1 \\ + Quebec & 2006 & 828.0 & 11.1 & 1006.0 & 13.4 \\ + Quebec & 2007 & 784.0 & 10.4 & 1076.0 & 14.3 \\ + Quebec & 2008 & 828.0 & 10.9 & 1172.0 & 15.4 \\ + Quebec & 2009 & 686.0 & 8.9 & 1030.0 & 13.4 \\ + Quebec & 2010 & 778.0 & 10.0 & 1129.0 & 14.5 \\ + Quebec & 2011 & 745.0 & 9.5 & 1095.0 & 14.0 \\ + \hline +\end{tabular} + + +} +\caption{Using Xtable} +\end{table} +This looks adequate, but lets see if Hmisc can do better... +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example part 4} +\small +\begin{table} +\resizebox{\linewidth}{!}{% +% latex.default(tab6, file = "", extracolheads = c("", "(x 1,000)", "\\%", "(x 1,000)", "\\%"), cgroup = c("", "LICO", "LIM"), n.cgroup = c(1, 2, 2), rgroup = c("Ontario", "Quebec"), n.rgroup = c(7, 7), table.env = FALSE, center = "none", rowlabel = "", col.just = c("c", "c", "c", "c", "c"), size = "tiny") +% +\tiny +\begin{tabular}{lccccccc} +\hline\hline +\multicolumn{1}{l}{\bfseries }&\multicolumn{1}{c}{\bfseries }&\multicolumn{1}{c}{\bfseries }&\multicolumn{2}{c}{\bfseries LICO}&\multicolumn{1}{c}{\bfseries }&\multicolumn{2}{c}{\bfseries LIM}\tabularnewline +\cline{4-5} \cline{7-8} +\multicolumn{1}{l}{}&\multicolumn{1}{c}{Year}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{Number of persons in low income}&\multicolumn{1}{c}{Poverty rate}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{Number of persons in low income}&\multicolumn{1}{c}{Poverty rate}\tabularnewline +&&&\multicolumn{1}{c}{{\scriptsize (x 1,000)}}&\multicolumn{1}{c}{{\scriptsize \%}}&&\multicolumn{1}{c}{{\scriptsize (x 1,000)}}&\multicolumn{1}{c}{{\scriptsize \%}}\tabularnewline +\hline +{\bfseries Ontario}&&&&&&&\tabularnewline +~~1&$2005$&&$1276$&$10.3$&&$1452$&$11.7$\tabularnewline +~~2&$2006$&&$1283$&$10.3$&&$1418$&$11.3$\tabularnewline +~~3&$2007$&&$1111$&$~8.8$&&$1418$&$11.2$\tabularnewline +~~4&$2008$&&$1187$&$~9.3$&&$1588$&$12.4$\tabularnewline +~~5&$2009$&&$1306$&$10.1$&&$1681$&$13.0$\tabularnewline +~~6&$2010$&&$1153$&$~8.8$&&$1608$&$12.3$\tabularnewline +~~7&$2011$&&$1182$&$~9.0$&&$1576$&$12.0$\tabularnewline +\hline +{\bfseries Quebec}&&&&&&&\tabularnewline +~~8&$2005$&&$~870$&$11.7$&&$1048$&$14.1$\tabularnewline +~~9&$2006$&&$~828$&$11.1$&&$1006$&$13.4$\tabularnewline +~~10&$2007$&&$~784$&$10.4$&&$1076$&$14.3$\tabularnewline +~~11&$2008$&&$~828$&$10.9$&&$1172$&$15.4$\tabularnewline +~~12&$2009$&&$~686$&$~8.9$&&$1030$&$13.4$\tabularnewline +~~13&$2010$&&$~778$&$10.0$&&$1129$&$14.5$\tabularnewline +~~14&$2011$&&$~745$&$~9.5$&&$1095$&$14.0$\tabularnewline +\hline +\end{tabular} + + + +} +\caption{Using Hmisc} +\end{table} +This looks a bit nicer I think. Lets go over the code in detail +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example: code} +\small +First, lets cast the data, drop \emph{Geography} and rename headers. +\begin{verbatim} +tab6<-cast(tab4,Geography+Year~Line+Statistic, + value="Value") +tab6<-tab6[,-1] +colnames(tab6)<- +c("Year","Number of persons in low income", + "Poverty rate","Number of persons in low income", + "Poverty rate") +\end{verbatim} +Now lets wrap our \emph{tab6} in Hmisc's latex function and avoid any unecessary file creation. Lets also set a font size. +\begin{verbatim} +latex(tab6,file='',size ='tiny', +\end{verbatim} +Add extra headers beneath our new column names. +\begin{verbatim} +extracolheads=c('','(x 1,000)','\\%', +'(x 1,000)','\\%'), +\end{verbatim} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hmisc example: code cont...} +\small +Now lets look at multi-line headers. We want the first 7 rows in one group and the next 7 in another. Then name the respective groups. We want the first row, then the next 2 and the next 2 in groups so name those as well +\begin{verbatim} +n.rgroup=c(7,7),rgroup=c('Ontario','Quebec'), +n.cgroup=c(2,2),cgroup=c('','LICO','LIM'), +\end{verbatim} +Remove any header for the rownames and center all the columns +\begin{verbatim} +rowlabel='',col.just=c('c','c','c','c','c'), +\end{verbatim} +Finally, and most importantly, remove the float (ie. remove \verb|\begin{table} \begin{center}| and the ends as well) so we can resize it later. +\begin{verbatim} +table.env=FALSE,center='none') +\end{verbatim} +\end{frame} + + + + \section{Sweave} \begin{frame} \frametitle{Section 3} @@ -1025,7 +1287,7 @@ \section{Beamer} \hlkwd{facet_grid}\hlstd{(.} \hlopt{~} \hlstd{Geography)} \end{alltt} \end{kframe} -\includegraphics[width=\maxwidth]{figure/unnamed-chunk-11} +\includegraphics[width=\maxwidth]{figure/unnamed-chunk-15} \end{knitrout} @@ -1036,7 +1298,7 @@ \section{Beamer} The last plot is not sized correctly. Playing with the fig.width and fig.height in the chunk options, we can get... \begin{knitrout} \definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor} -\includegraphics[width=\maxwidth]{figure/unnamed-chunk-12} +\includegraphics[width=\maxwidth]{figure/unnamed-chunk-16} \end{knitrout} diff --git a/Guide.toc b/Guide.toc index 4015daa..04d56e3 100644 --- a/Guide.toc +++ b/Guide.toc @@ -1,5 +1,5 @@ \beamer@endinputifotherversion {3.20pt} \beamer@sectionintoc {1}{GGPLOT2}{5}{0}{1} \beamer@sectionintoc {2}{Xtable and Hmisc}{17}{0}{2} -\beamer@sectionintoc {3}{Sweave}{36}{0}{3} -\beamer@sectionintoc {4}{Beamer}{43}{0}{4} +\beamer@sectionintoc {3}{Sweave}{44}{0}{3} +\beamer@sectionintoc {4}{Beamer}{51}{0}{4} diff --git a/README b/README index 55ecbaf..18cd9e3 100644 --- a/README +++ b/README @@ -1 +1,10 @@ -This is my read me file \ No newline at end of file +Hello! + +This is my read me file for my basic novice guide to Beamer-Sweave-ggplot. In this repository should be located the .csv file of the data, publicly available from Statistics Canada CANSIM product, the .pdf, the .tex, and many auxiliary files from the compilation. + +I am using a custom McGill .sty file that can be found here: +https://github.com/gsarkis/McGill-Beamer-Theme + +Disclaimer: This is a novice guide because I myself am a novice at Beamer and Sweave. I'm not an expert, and this is not expert advice. But it may be helpful for beginners. + +Thanks for reading! \ No newline at end of file diff --git a/figure/unnamed-chunk-1.pdf b/figure/unnamed-chunk-1.pdf index d92db32..a85cf50 100644 Binary files a/figure/unnamed-chunk-1.pdf and b/figure/unnamed-chunk-1.pdf differ diff --git a/figure/unnamed-chunk-2.pdf b/figure/unnamed-chunk-2.pdf index 8fedfa8..4de97a4 100644 Binary files a/figure/unnamed-chunk-2.pdf and b/figure/unnamed-chunk-2.pdf differ diff --git a/figure/unnamed-chunk-3.pdf b/figure/unnamed-chunk-3.pdf index 478c698..c59ea58 100644 Binary files a/figure/unnamed-chunk-3.pdf and b/figure/unnamed-chunk-3.pdf differ diff --git a/figure/unnamed-chunk-4.pdf b/figure/unnamed-chunk-4.pdf index 9bdeba5..9bf4c8f 100644 Binary files a/figure/unnamed-chunk-4.pdf and b/figure/unnamed-chunk-4.pdf differ