Last active
December 31, 2015 23:40
-
-
Save johnbaums/e799ebd3f9468a05e359 to your computer and use it in GitHub Desktop.
Add missing axes to a lattice multi-panel plot when as.table=TRUE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See http://stackoverflow.com/a/34552387/489704 for motivation and an example | |
# Based on code provided by StackOverflow user @user20650 | |
add_axes <- function() { | |
library(grid) | |
library(lattice) | |
l <- trellis.currentLayout() | |
pan <- which(l[nrow(l), ]==0) | |
if(length(pan) > 0) { | |
g <- grid.ls(print=FALSE) | |
ticks <- grid.get(g$name[grep("ticks.bottom.panel", g$name)][[1]]) | |
labels <- grid.get(g$name[grep("ticklabels.bottom.panel", g$name)][[1]]) | |
ax <- grobTree(ticks, labels) | |
invisible(sapply(pan, function(x) { | |
trellis.focus("panel", x, nrow(l)-1, clip.off=TRUE) | |
grid.draw(ax) | |
trellis.unfocus() | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment