From what I gather from the help of par
, the lwd
parameter differs from device to device. For x11
it states that "Line widths as controlled by par(lwd =) are in multiples of 1/96inch". Based on the defined lwd
, I needed to convert this width to the x and y units of the graph in order to correctly offset the following lines.
So now I have your lines able to turn a corner - some adjustments to the lines are still needed in order to get them to all end at the same length (e.g. subtract the offset from the last value in the series).
Example:
x <- c(1:10, rep(1, 10))
y <- c(rep(1, 10), 1:10)
lwd <- 20
x11() #lwd is multiples of 1/96 inches (from help info)
plot(y ~ x, t="l", lend=2, ljoin=2, lwd=lwd, col=3, xlim=c(0,11), ylim=c(0,11))
x.units.per.inch <- (par("usr")[2] - par("usr")[1]) / par("pin")[1]
y.units.per.inch <- (par("usr")[4] - par("usr")[3]) / par("pin")[2]
x.offset <- x.units.per.inch * 1/96 * lwd
y.offset <- y.units.per.inch * 1/96 * lwd
lines(x + x.offset, y + y.offset, lend=2, ljoin=2, lwd=lwd, col=2)
lines(x - x.offset, y - y.offset, lend=2, ljoin=2, lwd=lwd, col=4)