在我之前的问题中,我询问了如何将新点添加到现有的 grob 中,我发现我需要为新点指定一个视口,如果代码在同一环境中运行,这很容易。如果 grob 从类似于以下的函数返回怎么办:
getgrob = function(x, y) {
            require(grid)
            # x = 1:10
            # y = rnorm(10)
            plotvp = plotViewport(c(5, 5, 3, 3), name='plotvp')
            datavp = dataViewport(x, y, name='datavp')
            datapts = pointsGrob(x, y, pch=20, size=unit(1.3, 'mm'), name='datapts')
            xaxis = xaxisGrob()
            yaxis = yaxisGrob()
            xlab = textGrob('X Label', y=unit(-3, 'lines'), name='xlab')
            ylab = textGrob('Y Label', x=unit(-3, 'lines'), rot=90, name='ylab')
            plotbox = rectGrob()
            dataplot = gTree(children=gList(datapts,
                                            xaxis, yaxis,
                                            xlab, ylab,
                                            plotbox),
                             vp=datavp, name='dataplot')
            wholeplot = gTree(children=gList(dataplot),
                              vp=plotvp, name='wholeplot')
            wholeplot
        }
myplot = getgrob(1:10, rnorm(10))
现在我有一些新观点:
x = 1:10
y = rnorm(10)/2
我需要datavp视口来添加这些点,这只能通过myplotgrob 获得,在这种情况下,我如何访问视口?
 
