Removing borders in R plots for achieving Tufte’s axis

Consider the following graph:

x <- 1:100
y1 <- rnorm(100)
y2 <- rnorm(100)+100

par(mar=c(5,5,5,5))

plot(x,y1,pch=0,type="b",col="red",yaxt="n",ylim=c(-8,2),ylab="")
axis(side=2, at=c(-2,0,2))
mtext("red line", side = 2, line=2.5, at=0)

par(new=T)
plot(x,y2,pch=1,type="b",col="blue",yaxt="n",ylim=c(98,108), ylab="")
axis(side=4, at=c(98,100,102), labels=c("98%","100%","102%"))
mtext("blue line", side=4, line=2.5, at=100)

How can I remove the automatically generated borders and preserve just the axis lines, to achieve a Tufte’s style?

Answer

Add bty="n" in both plot commands.

For time series, add frame.plot=FALSE for the same effect.

For fancier Tufte axes, see http://www.cl.cam.ac.uk/~sjm217/projects/graphics/

Attribution
Source : Link , Question Author : Hugo Sereno Ferreira , Answer Author : Rob Hyndman

Leave a Comment