格子基于Grid Universe。连接放置在不同视口上的格子图面板应该很容易。但是似乎面板在两者之间形成了界限。
我想连接以下两个格子图的要点。但是the red line is cropped 。如何连接两个点?
谢谢!
library(grid)
library(lattice)
p1 <- xyplot(mpg ~ disp, mtcars,
panel= function(...){
grid.points(300,20, default.units="native",size=unit(4,"mm"),pch=16)
panel.xyplot( ... )
}
)
##p1
grid.newpage()
vlay <- viewport(layout=grid.layout(nrow=2, ncol=2),name="ejjoin")
pushViewport(vlay)
vpfig1 <- viewport(layout.pos.row = 1, layout.pos.col = 1:2,name = "vp11")
vpfig2 <- viewport(layout.pos.row = 2, layout.pos.col = 2,name = "vp12")
pushViewport(vpfig1)
print(p1,newpage=FALSE,prefix="figrow1")
upViewport() ##
pushViewport(vpfig2)
print(p1,newpage=FALSE,prefix="figrow2")
upViewport() ##
## Connect the points
##grid.ls(viewports=TRUE, grobs=FALSE)
seekViewport("figrow1.panel.1.1.vp")
grid.move.to(unit(300,"native"), unit(20, "native"))
seekViewport("figrow2.panel.1.1.vp")
grid.line.to(unit(300,"native"), unit(20, "native"),arrow=arrow(),gp=gpar(col="red",lwd=4))
upViewport() ##
答案 0 :(得分:0)
解决了!我必须选择另一个视口。 The solution 谢谢!
grid.ls(viewports=TRUE, grobs=FALSE, fullnames=TRUE)
seekViewport("figrow1.panel.1.1.vp")
grid.move.to(unit(300,"native"), unit(20, "native"))
##seekViewport("figrow2.panel.1.1.vp") ## Wrong!
seekViewport("figrow2.panel.1.1.off.vp")
grid.line.to(unit(300,"native"), unit(20, "native"),arrow=arrow(),gp=gpar(col="red",lwd=4))
upViewport() ##