[R] Truncating y axis

Wolfgang Viechtbauer wviechtb at s.psych.uiuc.edu
Sat Jun 28 17:43:44 CEST 2003


> I want to have a y-axis using matplot where the y axis is truncated as
> shown schematically below:

One (not so elegant) way is this:

# original data with one very large y value
x <- c(1, 2, 3, 4, 5)
y <- c(1000, 120, 110, 108, 104)
plot(x,y)

# truncated y-axis plot
y <- c(140, 120, 110, 108, 104)
plot(x,y, yaxt="n")
axis(side=2, at=c(100, 105, 110, 115, 120, 140), labels=c(100, 105, 110, 115, 120, 1000))
rect(0, 130, 1, 131, col="white", border="white")
par(xpd=T)
lines(x=c(0.7,1), y=c(130, 130))
lines(x=c(0.7,1), y=c(131, 131))

--
Wolfgang Viechtbauer




More information about the R-help mailing list