Formatting Charts in R

The default plot() layout is functional, but of dubious aesthetic value. While the ggplot2 does somewhat better, it is possible to configure the native plot() command with a few extra parameters.

This is an example of a default plot:

x = 0:20
y = x + runif(length(x))

plot(x, y, type='l')
plot() with default parameters

This particular layout is clean and minimalist:

x = 0:20
y = x + runif(length(x))

plot(x, y, type='l', 
	col="navy", lwd=3,
	las=1, fg="white", font.lab=2, 
	xaxs='i', yaxs='i',
	xlim=c(0, 20), ylim=c(0,25),
	panel.first = grid(nx=NA, ny=NULL, lty=1, col="gray"),
	xlab="X", ylab="f(X)")

abline(a=0, b=0, lwd=3)
Improved plot() layout