如何使用网格包绘制矩形

Vio*_*ola 5 r r-grid

我需要在图表上绘制一个矩形以突出显示不同的变化。我需要使用grid包。我尝试使用 ,grid.rect但它不起作用。我希望我的矩形看起来像图片上的那样。

在图片的左侧,您可以看到我的图表,在图片的右侧,我添加了矩形(在 Paint 中),就像我想要的那样。

在此处输入图片说明

library(grid)
library(lattice)
library(sandwich)

data("Investment")
Investment <- as.data.frame(Investment)

trellis.par.set(theme = canonical.theme("postscript", color=FALSE))
grid.newpage()
pushViewport(viewport(x=0, width=.4, just="left"))
print(barchart(table(Investment$Interest)),
  newpage=FALSE)
popViewport()
pushViewport(viewport(x=.4, width=.5, just="left"))
print(xyplot(Investment ~ Price, data=Investment, 
         auto.key=list(space="right"),
         par.settings=list(superpose.symbol=list(pch=c(1, 3, 16),
                             fill="white"))),
  newpage=FALSE)

popViewport()
Run Code Online (Sandbox Code Playgroud)