Splus/R graphics for theses and journal articles

Topics covered are:


setting fonts in R

After reproduction, labels on plots may be unclear if the defaults are used. Use the cex= (character expansion) and font= options to get a bold font and a larger than default size. Note that R has a slightly different way of assigning bold fonts than Splus. Note also that Greek letters can be used in R plots.

An example in R is:


x<-1:10
y<-sin(x)

par(mfrow=c(2,1))

plot(x,y,xlab="time", ylab="sin(t)")
title("A sample plot")
text(5, 0, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))

plot(x,y,xlab="time", ylab="sin(t)",font=2,cex=1.2,font.lab=2,cex.lab=1.2)
title("A sample plot",cex.main=1.5)
text(5, 0, expression(hat(bold(beta)) == (bold(X)^t * bold(X))^{bold(-1)}
  * bold(X)^t * bold(y)))


legends and captions

With use of legends and captions, plots should be self-explanatory so that reader does not have to read the body of the writing to understand the plots. For example, if a plot has curves with solid, dashed and dotted lines, these should be indicated with legend() in R/Splus or a caption in LaTeX.


boxplots and histograms

In some version of R and Splus, histograms and boxplots might be filled with black areas. This uses extra toner on a laser printer and does not look good after photocopying in journal articles. Recommended options are given in the code given below.

Note that boxcol=0 for boxplot and col=0 for hist are not needed for v 2 of R, as the default is white rectangles for v 2; these are useful in older versions of R and Splus.

set.seed(12345)
x<-rnorm(40)
y<-rnorm(40,1)
par(mfrow=c(2,1))
boxplot(x,y,names=c("length","width"),ylab="cm",
  boxcol=0,medline=T,medcol=1,medlwd=1,main="random numbers",cex=.5)
hist(x,col=0,xlab="length",ylab="freq")
mtext(side=3,line=5,"Example of boxplot and histogram with no black fill")