Skip to content

Instantly share code, notes, and snippets.

@gaberoo
Created February 5, 2013 15:05
Show Gist options
  • Save gaberoo/4714995 to your computer and use it in GitHub Desktop.
Save gaberoo/4714995 to your computer and use it in GitHub Desktop.
A replacement for R's "axis()" function that uses intersecting axes rather than the ugly stand-alone axes.
intersecting.axis <- function(side, at = NULL, labels = TRUE,
line = NA, pos = NA, outer = FALSE, lty = "solid",
lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL,
hadj = NA, padj = NA, ...) {
if (! outer) {
x.range <- extendrange(par("usr")[1:2],f=-0.01)
y.range <- extendrange(par("usr")[3:4],f=-0.01)
pos <- NA
xline <- c(NA,NA)
yline <- c(NA,NA)
switch(side,
{ xline <- x.range; yline <- rep(min(y.range),2); pos <- min(y.range) },
{ xline <- rep(min(x.range),2); yline <- y.range; pos <- min(x.range) },
{ xline <- x.range; yline <- rep(max(y.range),2); pos <- max(y.range) },
{ xline <- rep(max(x.range),2); yline <- y.range; pos <- max(x.range) })
lines(xline,yline,lwd=lwd,lty=lty)
axis(side,pos=pos,lwd=0,lwd.ticks=lwd.ticks,col.ticks=col.ticks,at=at,labels=labels,...)
} else {
stop("Not implemented for 'outer = TRUE'.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment