S(SPlus) Source Code
Many possibilities exist that are very dependent on the data being shown, this is intended as a general version to show the basic ideas.

cave.plot <- function(x, y, x.top, y.top, overlap, xaxis.at, xaxis.lab,
        yaxis.at, yaxis.lab, xlab="", ylab="")
{

        yl <- range(y)
        yd <- diff(yl)
        ymax <- yl[2] + ((100 - overlap)/100)*yd
        right.at <- ymax - yaxis.at
        y.top <- ymax - y.top
        xall <- c(x,x.top)[!is.na(c(x,x.top))]
        xl <- c(min(xall)-.03*diff(range(xall)),
                max(xall)+.03*diff(range(xall)))
        plot(x,y,type='h',xlab=xlab,ylab=ylab,axes=F,
                ylim=c(0,ymax),xlim=xl, yaxs = "i", xaxs = "i")
        usr <- par("usr")
        #gray background
        polygon(x = usr[c(1,2,2,1)], y = usr[c(3,3,4,4)], col=0.025, border=F)
        segments(x,rep(0,length(x)),x,y)
        axis(2,cex=.4,at=yaxis.at,labels=yaxis.lab,cex=.5)
        box()
        par(mgp=c(.75,.25,0))
        axis(1,at=xaxis.at,labels=xaxis.lab,tck=-.01,cex=.7)
        axis(3,at=xaxis.at,labels=xaxis.lab,tck=-.01,cex=.7)

        segments(x.top,rep(ymax,length(x.top)),x.top,y.top)
        axis(4,cex=.4,at=right.at,labels=yaxis.lab,cex=.5)
        box()
        usr <- par("usr")
        #these two lines erase the corners of the box to help
        #visually separate the top and bottom
        segments(usr[1:2],c(ymax,0),usr[1:2],
                c(max(yaxis.at), min(right.at)), col=0)
        segments(c(usr[1],max(xall)), c(ymax,0),
                c(min(xall), usr[2]),c(ymax,0),col=0)
}


Other versions of cave.plot are possible, for example showing one or both time series as curves instead of segments, or highlighting certain regions of the plot.

Copyright (C) 1998 by Bell Laboratories, Lucent Technologies

Permission to use, copy, modify, and distribute this software and its documentation for noncommercial purposes and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.