R workshop: handout #4

Mike Hammond
U. of Arizona
  1. Error bars
    1. Miquel asked about error bars in a barplot. Here's a little code to do that.
  2. Using R in papers
    1. xtable() converts an R object into a table that can be printed as LaTeX or as HTML.
      g <- read.table('gender.txt',header=T)
      attach(g)
      library(xtable)
      g.lm <- lm(age ~ weight)
      print(xtable(g.lm))
      print(xtable(g.lm), type='HTML')
      
    2. Exporting a plot using the GUI menus: a barplot and a barplot with error bars.
    3. Here's a MSWord document with graphics constructed like this.
    4. To understand Sweave, you have to first understand LaTeX. Here's a LaTeX source document. Graphics are inserted in parallel fashion to the MSWord document above. This document compiles to this.
    5. R CMD Sweave filename.Rnw converts a sweave file into a LaTeX file. For example: sw2.Rnw can be converted to sw2.pdf.
      R CMD Sweave swtest.Rnw
      latex swtest
      latex swtest
      dvipdf swtest