Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active August 20, 2019 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/a536db05e38ed86a7f59bc26837f24db to your computer and use it in GitHub Desktop.
Save yutannihilation/a536db05e38ed86a7f59bc26837f24db to your computer and use it in GitHub Desktop.
It seems the grob settings are vectorized over x and y
library(grid)

g <- textGrob(
  label = c("1", "2", "3"),
  gp = gpar(
    fontsize = 1:3 * 50,
    cex = 1,
    fontfamily = "",
    fontface = "plain",
    col = ggplot2::alpha(c("black", "red"), 0.5)
  )
)

grid.newpage()
grid.draw(g)

g$x <- unit(c(0.5, 0.5), "npc")

grid.newpage()
grid.draw(g)

g$x <- unit(1:6 * 0.05 + 0.2, "npc")
g$y <- unit(1:6 * 0.05 + 0.2, "npc")

grid.newpage()
grid.draw(g)

Created on 2019-08-20 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment