在R网格图形中,如何在grobTree中裁剪grob对象?以某种方式,我只需要调用grid.draw
即可绘制裁剪的grob。
例如,当我直接绘制我的东西时:
# Direct plotting ----
library(grid)
grid.newpage()
vp <- viewport(x = 0.25, y = 0.25, width = 0.5,height = 0.5,
just = c("left", "bottom"), name = "vp")
pushViewport(vp)
grid.rect()
grid.polygon(x = c(0.4,0.9, 1.4, 0.9), y = c(0.5, 0.75, 0.5, 0.25),
gp = gpar(lty = 3))
grid.clip()
grid.polygon(x = c(0.4,0.9, 1.4, 0.9), y = c(0.5, 0.75, 0.5, 0.25),
gp = gpar(fill = "grey"))
我获得了剪切的版本:
但是当我尝试将其放入grobTree对象(以供以后操作)时,它不起作用:
# Indirect plotting ----
library(grid)
aGrob <- grobTree()
vp <- viewport(x = 0.25, y = 0.25,,width = 0.5,,height = 0.5,
just = c("left", "bottom"), name = "vp")
r1 <- rectGrob(vp = vp)
p1 <- grid.polygon(x = c(0.4,0.9, 1.4, 0.9), y = c(0.5, 0.75, 0.5, 0.25),
gp = gpar(lty = 3), vp = vp)
c1 <- clipGrob(vp = vp)
p2 <- grid.polygon(x = c(0.4,0.9, 1.4, 0.9), y = c(0.5, 0.75, 0.5, 0.25),
gp = gpar(fill = "grey"), vp = vp)
aGrob <- grobTree(aGrob, r1, p1, c1, p2)
grid.newpage()
grid.draw(aGrob)
我得到一个未压缩的版本:
如何在我的grobTree对象中拥有剪切的版本?
尝试在视口clip = TRUE
中使用vp
,>