两个矩形之间的曲线未显示

Curve between two rectangles is not shown

我试图用弯曲的箭头连接两个矩形,但没有绘制曲线。你能帮帮我吗?

谢谢!

library(grid)

grid.newpage()

pushViewport(plotViewport(c(2, 2, 2, 2)))

xis <- c(0,0.25)
for (i in 1:2)
{
  grid.roundrect(x=unit(xis[i],"npc"), y=unit(1,"npc"),
                 width=1.4*stringWidth("very snug"),
                 height=1.1*unit(2, "line"),
                 just=c("left", "top"), gp=gpar(col="red"),
                 name = paste0("rectangulo",i))
  
  grid.text(paste0("very snug",i),x=xis[i]+0.005, y=unit(0.992,"npc"),
            just=c("left", "top"),name = paste0("texto",i))

  grid.text(paste0("Pedro",i),x=xis[i]+0.005, y=unit(0.95,"npc"),
            just=c("left", "top"),name = paste0("pedro",i))
  
  }

grid.curve(grobX("texto1", 0)+unit(2,"mm"), grobY("texto1", 0),
           grobX("rectangulo2", 180), grobY("pedro2", 180),
           curvature=0.5)

查看 '?grobX' 它说 grobX()grobY() 函数需要他们的第一个参数是

A grob, or gList, or gTree, or gPath.

但是您的代码提供了字符串。绘制矩形后,运行 此代码使用 gTree 对象进行抓取和输入,其中包含感兴趣的 grobs

grab <- grid.grab()

grid.curve(grobX(grab$children$texto1, 0)+unit(2,"mm"), grobY(grab$children$texto1, 0),
           grobX(grab$children$rectangulo2, 180), grobY(grab$children$pedro2, 180),
           curvature=0.5)