General guide for creating publication quality tables using R, Sweave, and LaTeX

30,093

Solution 1

Just to tie this up with a nice little bow at the time of current writing, the best existant tutorials on publication-quality tables and usage scenarios appear to be an amalgamation of these documents:

Going beyond the scope of what currently exists, you may want to ask the author of The Joy of Sweave for a document on publication-quality tables specifically. It seems like he's gone above and beyond this problem in his research. In addition to the questions you've raised, this space specifically could use a style guide that, flatly, does not currently exist.

And, as mentioned in the question errata, this is a perfect example of a question for https://tex.stackexchange.com/. I encourage you to continue to ask specific questions there when you run into any difficulties in your current projects.

Solution 2

The package stargazer can create publication-quality - incl. using templates designed to resemble existing academic journals - from commonly used R statistical functions and packages (lm, glm, plm, svyglm, survival, pscl, AER, and others). Also good for creating summary statistics tables, and can directly output data frame content as well.

Solution 3

There is a tabular function in the tables package which addresses formatting, alignment and label operations. The package has a vignette which is a good starting point.

Solution 4

xtable has worked fine for me so far. In combination with siunitx, and when necessary, longtable, it can produce pretty effective tables, in my opinion. With packages like booktabs and caption, the aesthetics can be pleasing too.

I am not sure this level of detail was asked for by the OP, but for what it's worth, the basic implementation could be something along these lines: https://tex.stackexchange.com/questions/41067/caption-for-longtable-in-sweave/41183#41183 (my own answer to another question).

Share:
30,093

Related videos on Youtube

Jeromy Anglim
Author by

Jeromy Anglim

I am a Senior Lecturer in the School of Psychology at Deakin University bridging I/O psychology and statistics. I'm quite active on the Cognitive Sciences and Statistics Stack Exchanges. You can find me also on: Twitter: @JeromyAnglim My blog on psychology and statistics: http://jeromyanglim.blogspot.com

Updated on July 15, 2022

Comments

  • Jeromy Anglim
    Jeromy Anglim almost 2 years

    There are a range of tools available for creating publication quality tables using R, Sweave, and LaTeX. In particular, there are helper functions like latex in the Hmisc package, and xtable in the xtable package. I've also often written my own code so that I could have complete control over table formatting (e.g., see this example).

    However, when preparing publication quality tables a range of issues often arise:

    • how and when to apply numeric formatting
    • how to precisely control alignment of columns and cells
    • how to precisely control cell borders
    • how to convert variable labels to variable names
    • and so on

    Beyond the high level issues of specifying the desired table format, there are issues of implementation.

    • When should a helper function such as xtable be used?
    • Which helper function should be used in a given situation?
    • How can the default output of helper functions be customised to particular requirements?

    Question

    It seems to me that the above issues are deserving of a detailed textbook-style introduction.

    Are there any online or offline resources that provide a detailed overview of how to produce publication quality tables using R, Sweave, and LaTeX, and that address the issues discussed above?

    • Ari B. Friedman
      Ari B. Friedman about 12 years
      I would add knitr to the list. It seems to solve a lot of the integration issues with Sweave and cacheing and tikz. But good q.
    • Yihui Xie
      Yihui Xie about 12 years
      in fact I had the similar question a few months back as well: github.com/yihui/knitr/issues/53 I'm eager to see how other people answer it. For me, I almost always avoid tables... when I have to use tables, I almost always use xtable.
    • Vincent Zoonekynd
      Vincent Zoonekynd about 12 years
      I personnaly find Hmisc's latex function more flexible than xtable. The Booktabs (to fine-tune the spaces) and Datatool (to read CSV files) LaTeX packages may also be useful.
    • Brandon Bertelsen
      Brandon Bertelsen about 12 years
      I find latex from Hmisc far too complicated. Everything that I generally need to be able to do is done in print.xtable() and xtable(). If you're creating something for publication, you are ALWAYS going to have to massage anything that's generated automatically. You can create wrapper functions for xtable, print.xtable and latex that suit particular situations.
    • Lorin Hochstein
      Lorin Hochstein about 12 years
      You might have better luck asking at tex.stackexchange.com
    • MrGomez
      MrGomez about 12 years
      I found this PDF and this one to be greatly informative on the referenced issues. Unfortunately, I cannot find anything within this space that's as full-bodied and complete as the LaTeX reference manual or the documentation on my favorite editor, AUCTeX. A style guide would also be very nice.
    • zach
      zach about 12 years
      I would also add 'Brew'. I though this was a great post for learning the basics: learnr.wordpress.com/2009/09/09/…
  • Artem Klevtsov
    Artem Klevtsov over 11 years
    tables package is the very excelent addition for Hmisc::latex.