【问题标题】:Connecting Lattice graphs in different grid viewports在不同的网格视口中连接晶格图
【发布时间】:2019-09-20 01:53:03
【问题描述】:

Lattice 基于网格宇宙。连接放置在不同视口上的格图面板应该很容易。但似乎面板裁剪了它们之间的界限。

我想把下面两个格子图的大点连接起来。但是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() ##

【问题讨论】:

    标签: r lattice r-grid


    【解决方案1】:

    解决了!我必须选择另一个视口。 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() ##
    
    

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 2010-10-03
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多