I am investigating the new pattern functionality of grid
. So far, I can cross-hatch a rectangle:
library(grid)
# Note that using absolute coordinates like "cm" for
# x and y does not work
cross <- grobTree(
linesGrob( x= unit(c(0,1),"npc"), y= unit(c(0,1),"npc")),
linesGrob( x= unit(c(0,1),"npc"), y= unit(c(1,0),"npc")))
cpat <- pattern(cross,
width = unit(1,"cm"),
height = unit(1,"cm"),
extend = "repeat")
rect <- rectGrob(
width = unit(5, "cm"),
height = unit(5, "cm"),
gp= gpar(fill = cpat))
grid.newpage()
grid.draw(rect)
But I can neither rotate my object without messing up:
grid.newpage()
grid.draw(grobTree(rect,vp=viewport(angle=20)))
And I also cannot rotate the pattern inside the object because each time, it does not rotate the direction in which to repeat the pattern:
vp <- viewport(angle = 30)
cross <- grobTree(
linesGrob( x= unit(c(0,1),"npc"), y= unit(c(0,1),"npc")),
linesGrob( x= unit(c(0,1),"npc"), y= unit(c(1,0),"npc")),
vp = vp)
cpat <- pattern(cross,
width = unit(1,"cm"),
height = unit(1,"cm"),
extend = "repeat")
rect <- rectGrob(
width = unit(5, "cm"),
height = unit(5, "cm"),
gp= gpar(fill = cpat))
grid.newpage()
grid.draw(rect)
How can I rotate the direction in which the pattern is repeated?
EDIT: This is on R 4.3.1