[R] Error with strwidth after lattice graphic drawn

Frank E Harrell Jr f.harrell at vanderbilt.edu
Sun Nov 21 16:52:33 CET 2004


Uwe Ligges wrote:
> Prof Brian Ripley wrote:
> 
>> On Sat, 20 Nov 2004, Frank E Harrell Jr wrote:
>>
>>> In
>>>
>>> platform i386-pc-linux-gnu
>>> arch     i386
>>> os       linux-gnu
>>> system   i386, linux-gnu
>>> status
>>> major    2
>>> minor    0.1
>>> year     2004
>>> month    11
>>> day      15
>>> language R
>>>
>>> I'm getting an error when using strwidth after a lattice graphic is 
>>> drawn:
>>>
>>> library(lattice)
>>> xyplot(runif(20) ~ runif(20))
>>> strwidth('xxx')
>>>
>>> Error in strwidth("xxx") : invalid graphics state
>>>
>>> Any help appreciated.  I have version 2.0.1 of grid and version 
>>> 0.10-14 of lattice.
>>
>>
>>
>> The advice is `don't do that'!
>>
>> strwidth() is a base graphics command, and will only work if a device 
>> is currently plotting base graphics.  Lattice is built on grid, which has
>> stringWidth().
>>
> 
> ... and convertWidth() is useful to display stuff afterwards in an 
> interpretable way  ...
> 
> Uwe Ligges
> 

Thanks Uwe and Brian.  Before the latest versions, grid would let me use 
ordinary graphics functions to deal with the currently rendered plot 
after I did par(usr=c(0,1,0,1)), so I was lazy.  I changed my code to 
use specific grid functions.

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list