R/Adding letters

From QERM Wiki
Revision as of 00:22, 22 July 2010 by Ian (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Adding letters to identify sub-figures

Various journals want little letters in the corner. Here's some code to do it:

makeletter <- function(letter='a',position='topleft',xfrac=0.05,yfrac=0.05,...){
  # puts a letter into the corner of a panel to match CJFAS requirements
  # very similar to something Trevor Branch (and who knows how many others)
  # created independently
  if(letter%in%1:9) letter <- letters[letter]
  p <- par('usr')
  if(position=='topleft') x <- p[1] + xfrac*diff(p[1:2])
  if(position=='topright') x <- p[2] - xfrac*diff(p[1:2])
  y <- p[4] - yfrac*diff(p[3:4])

Apply using something like:

for(i in 1:4){plot(0); makeletter(i)}
Personal tools