# Adding a 'broken axis' to a plot

We've all seen a plot with a 'broken axis' --- e.g., the axis goes from 0 to 9 in units of 1, then shows a 'break' (//) and then continues from 100 to 200 in units of 20.

In R, you can create a broken axis but it takes a lot of trial and error. Here's an example. The most important thing to remember is that, in R, the length of X value must be the same as the length of your Y values.

```library(Hmisc)
library(Design)

plot(seq(from = 0, to = 2, by = 0.5), # X
seq(from = 0, to = 4, by = 1), # Y --- *** X and Y must have the same length ***
axes=FALSE, # set up but don't plot the axes
type="n", xlab="X", ylab="Y")
# Add break lines along x-axis
text("l", x = 1.20, y = 0, srt = -45, font = 2)
text("l", x = 1.25, y = 0, srt = -45, font = 2)
lines(x = c(0, 1.19), y = c(0,0), lwd = 2)
lines(x = c(1.25, 4.0), y = c(0,0), lwd = 2)
# Add break lines along y-axis
text("l", y = 1.15, x = 0, srt = -45, font = 2)
text("l", y = 1.25, x = 0, srt = -45, font = 2)
lines(y = c(0, 1.15), x = c(0,0), lwd = 2)
lines(y = c(1.27, 4), x = c(0,0), lwd = 2)
# Add x-axis (tick marks and labels)
mtext("l", side = 1, line = -1.25, at = seq(0, 2, 0.5), font = 2)
axis(side = 1, at = seq(0, 2, 0.5), line = -1, tick = FALSE,
labels = c("0.0", "0.5", "1.0", "5.5", "6.0"))
# Add y-axis (tick marks and labels)
mtext("l", side = 2, line = -1.20, at = seq(0, 4, 0.5), font = 2)
axis(side = 2, at = seq(0, 4, 0.5), line = -1, tick = FALSE,
labels = as.character(c(seq(from = 0, to = 4, by = 2),
seq(from = 100, to = 200, by = 20))))
```
Topic revision: r2 - 14 Nov 2006, TheresaScott

• Biostatistics Webs Copyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback