celestialgod

margin text

Apr 8th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.08 KB | None | 0 0
  1. library(lattice)
  2. library(grid)
  3.  
  4. leftText <- "words\nwords2\nwords3"
  5. rightText <- "words\nwords2"
  6. bottomPadding <- (max(sapply(gregexpr("\n", c(leftText, rightText)), length)) + 1L) * 2 + 2
  7.  
  8.  
  9. xyplot(
  10.   y ~ x, data.frame(x = rnorm(100), y = rnorm(100)),
  11.   par.settings = list(layout.heights = list(bottom.padding = bottomPadding)),
  12.   panel = function(x, y, ...) {
  13.     panel.xyplot(x, y, ...)
  14.     xscale <- current.viewport()$xscale
  15.     yscale <- current.viewport()$yscale
  16.     pushViewport(viewport(width = 2, height = 2, clip = TRUE))
  17.     pushViewport(viewport(width = 0.5, height = 0.5, xscale = xscale, yscale = yscale))
  18.     grid.text("v", unit(c(-0.5, 0, 0.5), "native"), unit(1, "npc") + unit(1, "mm"), c("center", "bottom"))
  19.     grid.text(c("L", "U"), unit(0, "npc") - unit(2, "mm"), unit(c(-2, 2), "native"), c("center", "bottom"),
  20.               gp = gpar(col = "red"))
  21.     popViewport(2)
  22.   },
  23.   page = function(page){
  24.     grid.text(leftText, 0.02, 0.02, c("left", "bottom"))
  25.     grid.text(rightText, 0.98, 0.02, c("right", "bottom"))
  26.   }, scales = list(tck = c(1, 0))
  27. )
Add Comment
Please, Sign In to add comment