[R] grid's viewports

M.Kondrin mkondrin at hppi.troitsk.ru
Tue Dec 30 16:48:58 CET 2003


Hello!
There is something wrong with nested viewports in grid package (I have 
tested it in R-1.8.0, may be it is different in other versions). Here is 
an simple example of a feature which seems strange to me:

x11()

rec<-T

push.viewport(viewport(xscale=c(-10,10),yscale=c(-10,10),gp=gpar(col="magenta")),recording=rec)

#Parent viewport with scales -10:10

grid.text(x=0,y=0,label="test",default.units="native",vp=viewport(x=-3,y=-3,width=0,height=0,default.units="native",gp=gpar(col="red")))->j

#Create a text label at position 0,0  in a nested viewport with 
coordinates -3,-3 relative to parent viewport

grid.edit(j,vp=viewport(x=5,y=5,width=0,height=0,default.units="native",gp=gpar(col="green")))

#Drag the text label to different position

pop.viewport(recording=rec)

push.viewport(viewport(xscale=c(-100,100),yscale=c(-100,100)),recording=rec)

#Create new parent viewport with scales -100:100

grid.edit(j,vp=viewport(x=5,y=5,width=0,height=0,default.units="native"))

#I would expect that the position of text became closer to the center of 
device but this does not happen. So it looks like the text label
remember its initial parent viewport.

pop.viewport(recording=rec)

So I can not reparent grob's viewports (although editing of grob's 
viewport works fine). It seems to me what pushing/popping viewports 
takes care of proper viewport's reparenting but it is not true. Changing 
recording parameter in push.viewport does not help (in the case 
rec<-FALSE text label does not show at all)




More information about the R-help mailing list