R, Statistics and Visualization

R Reporting Part 8: Using LaTeX to Create Posters

This is the eigth of a series of articles on how to use R, RStudio and TexMaker to prepare presentations and batch jobs for automated reporting on a web server or Microsoft SharePoint server. The series is based upon the presentation that I did at the February 27, 2016 Dallas R User Group Meetup. Because the presentation was primarily a demonstration, there really isn’t a presentation to distribute; this series covers the topics from the presentation/demonstration. The series will eventually include the following articles as I complete them over the next couple of weeks:

The series of articles describes the process for daily batch jobs that generate the Daily Econometric Graphs web page which includes links to the same econometric charts in several formats, all generated through the same R code:

All of the examples are based upon the knitr R package; you should reference the knitr documentation, as this article is not a replacement for the knitr documentation.

Example source is available in images/documents/econometric_source.zip.

LaTeX Poster Styles

Because LaTeX was written by and for academics and professionals in math and science who need to create posters for conferences and other displays, several authors have created LaTeX packages to make it easy to create posters. Here are a few of the major packages:

  • Baposter from Brian Amberg is easy to use but has a relatively fixed display style.
  • Beamerposter uses Beamer style operations.
  • A0poster is perhaps the most flexible of the various poster packages, but with flexibility comes some complexity.

The example that follows will use BAposter, as it is probably the easiest to get working. The example poster is a PDF file Useful Econometrics Poster.

BAPoster Example

The code for the example poster uses the knitr chunk syntax discussed earlier in this series of articles in R Reporting Part 3: Using Rhtml for Batch Web Reporting and set up using the read_chunk("econometric_charts_chunks.R") call in the prologue of the LaTeX/knitr file:

<<prolog,message=FALSE,echo=FALSE,error=FALSE,warning=FALSE,dev=c('pdf','png','jpeg')>>= #install.packages(c("dplyr","magrittr","assertr","ggvis","googleVis","htmlwidgets","networkD3","rCharts","qtlcharts","dygraphs","d3heatmap")) require(ggplot2) require(dplyr) require(magrittr) require(assertr) require(ggplot2) require(fImport) require(reshape2) require(scales) require(knitr) #library(RCurl) setwd("~/svn_work/Consulting_Business/web_site/articles/econometric_charts/src/R") options('download.file.method'='wget') read_chunk("econometric_charts_chunks.R") @ \documentclass[a0paper,portrait]{baposter} \usepackage{color} \definecolor{mssDeepBlue}{rgb}{0.1367188,0.375,0.5742188} % new RGB values \definecolor{mssCyan}{rgb}{0.0,0.6210938,0.8515625} \definecolor{mssGreen}{rgb}{0.4101562,0.7421875,0.15625} \definecolor{mssCyanLight}{rgb}{0.0,0.3105469,0.4257812} \usepackage{hyperref} \usepackage{hyperxmp} \usepackage{ifplatform} % % % \ifwindows \newcommand{\mssPathDef}{C:/Users/bwmoore/Documents} \else \newcommand{\mssPathDef}{/home/bwmoore} \fi \begin{document} \background{} \begin{poster}{ background=none, colspacing=0.7em, textborder=roundedleft, headerborder=none, headershape=roundedright, headerheight=0.134\textheight,% this defines height of box reserved for title, name, etc. %another declarations } {} {Useful Econometrics} {Bruce Moore \\ Moore Software Services LLC \\ Coppell, TX USA \\ moorebw@mooresoftwareservices.com} { \includegraphics[width=7cm,angle=0]{"/home/bwmoore/svn_work/Consulting_Business/VG_Visuals/Dropbox/LOGOS/Logo - Tagline Below/MOORE LOGO Tagline"}} \setlength\parindent{24pt} % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Column 1 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \headerbox{Purpose}{name=purpose,column=0,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ \paragraph{}This poster provides example econometrics to demonstrate using RStudio to generate a poster. } % % Column 1 Box 2 % \headerbox{Data Source}{name=dataSource,column=0,below=purpose,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ \paragraph{}The data for this poster was pulled from the St. Louis Federal Reserve FRED2 system using the fImport R package. \paragraph{}The poster uses the \LaTeX\ \href{https://www.brian-amberg.de/uni/poster/}{BAposter} package and was composed in RStudio and generated using the knitr R package. It was formatted for A0 printing (33.11 by 46.81 inches), although BAposter supports other page sizes. \paragraph{}Lists use the normal \LaTeX\ list itemize environment. For example, the data series used in this poster are \begin{itemize} \item Swap rates \item Used Car and Rruck Consumer Price Index \item Median Household Income \item Unemployment Rate \item Mortgage Delinquency \end{itemize} } % % Column 1 Box 3 % \headerbox{Contact Information}{name=contact,column=0,below=dataSource,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ \begin{center} Bruce Moore \\ bwmoore@mooresoftwareservices.com \\ +1 (972) 652-0254 \\ \includegraphics[width=.27\textwidth]{"/home/bwmoore/svn_work/Consulting_Business/sales_presentations/business_cards/images/bwmoore_tiny"} \end{center} } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Column 2 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \headerbox{Cost of Funds}{name=costOfFunds,column=1,span=2,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << costOfFunds,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg"),fig.width=6,fig.height=3,dpi=200>>= @ %\includegraphics[width=\linewidth]{\mssPathDef/svn_work/Consulting_Business/web_site/articles/econometric_charts/src/R/images/figures/costOfFunds-1.png} } % % Column 2 Box 2 % \headerbox{Auto CPI}{name=autoCPI,column=1,below=costOfFunds,boxheaderheight=1.0cm,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << autoCPI,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg")>>= @ } % % Column 2 Box 3 % \headerbox{Mortgage Delinquency}{name=mortDelinquncy,column=1,below=autoCPI,boxheaderheight=1.0cm,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << mortDelinquency,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg")>>= @ } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Column 3 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Column 3 Box 2 % \headerbox{Median Household Income}{name=medianHouseholdIncome,column=2,below=costOfFunds,boxheaderheight=1.0cm,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << medianHouseholdIncome,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg")>>= @ } % % Column 3 Box 3 % \headerbox{Unemployment}{name=unemployment,column=2,below=medianHouseholdIncome,boxheaderheight=1.0cm,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << medianHouseholdIncome,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg")>>= @ } \end{poster} \end{document}

Set Up Defaults

The first step is to set the various global parameters for the poster, for complete information on the various options, see the BAPoster documentation.

\background{} \begin{poster}{ background=none, colspacing=0.7em, textborder=roundedleft, headerborder=none, headershape=roundedright, headerheight=0.134\textheight,% this defines height of box reserved for title, name, etc. %another declarations } {} {Useful Econometrics} {Bruce Moore \\ Moore Software Services LLC \\ Coppell, TX USA \\ This email address is being protected from spambots. You need JavaScript enabled to view it.} { \includegraphics[width=7cm,angle=0]{"/home/bwmoore/svn_work/Consulting_Business/VG_Visuals/Dropbox/LOGOS/Logo - Tagline Below/MOORE LOGO Tagline"}} \setlength\parindent{24pt}

The bracket pairs contain the following:

  • The first bracket pair contains the key value options that set up the block shapes and other parameters
  • The second bracket pair contains the eyecatcher text; this is not used on this poster
  • The third bracket pair contains the poster title
  • The fourth bracket pair contains the poster authors
  • The final bracket pair contains the logo or header graphic for the poster

Creating a Text Box for a Single Column

BAPoster uses the headerbox tag to generate each box on the poster:

\headerbox{Purpose}{name=purpose,column=0,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ \paragraph{}This poster provides example econometrics to demonstrate using RStudio to generate a poster. }

The bracket pairs on the tag are as follows:

  • The first bracket pair contains the text for the heading
  • The second bracket pair contains the keywords for the tag, including these important tags:
    • name is required and is needed to establish the relative position of boxes within a column.
    • column is required to determine in which column the box should be placed
    • borderColor and the other keywords are optional but will be used in almost all cases.
  • The third bracket pair contains the text for the box. This can include any LaTeX tags for tables, lists, math, as long as the output will fit on the poster.

Creating the Second Text Box in a Column

The second and subsequent text boxes in a column are identical to the first but must have a below keyword to reference the text box that is immediately above:

\headerbox{Data Source}{name=dataSource,column=0,below=purpose,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ \paragraph{}The data for this poster was pulled from the St. Louis Federal Reserve FRED2 system using the fImport R package. \paragraph{}The poster uses the \LaTeX\ \href{https://www.brian-amberg.de/uni/poster/}{BAposter} package and was composed in RStudio and generated using the knitr R package. It was formatted for A0 printing (33.11 by 46.81 inches), although BAposter supports other page sizes. \paragraph{}Lists use the normal \LaTeX\ list itemize environment. For example, the data series used in this poster are \begin{itemize} \item Swap rates \item Used Car and Rruck Consumer Price Index \item Median Household Income \item Unemployment Rate \item Mortgage Delinquency \end{itemize} }

Creating a Text Box that Spans Columns

To emphasize a point, it will frequently be useful to create a text box that spans columns, as is done in the “Cost of Funds” block on this poster using the span keyword:

\headerbox{Cost of Funds}{name=costOfFunds,column=1,span=2,borderColor=mssDeepBlue,headerColorOne=mssDeepBlue,headerColorTwo=mssDeepBlue,boxshade=none,headerFontColor=white}{ << costOfFunds,echo=FALSE,message=FALSE,warning=FALSE,error=FALSE,pdf.compress=TRUE,eval=TRUE,fig.path="images/figures/",dev=c("png","pdf","svg"),fig.width=6,fig.height=3,dpi=200>>= @ }

This text box incorporates R code that will be evaluated by the knitr package. knitr does not know the size of the LaTeX text box, so you will probably want to use the fig.width and fig.height keywords for the chunk to set the relative dimensions that you want for any graphics so that the proportions match what you need in the text box.

We use cookies to ensure you get the best experience on our website.