[R] textplot() in gplots causes problems (0x9)

Gregory Warnes gregory.warnes at mac.com
Fri Nov 2 15:29:59 CET 2007


Hi Jonas,

You are correct that manually setting cex won't entirely remove the  
warning messages (note: these are *warnings* not *errors*).  It will  
reduce them greatly, from, perhaps 40, down to 3 or so.

Since the tab character won't be properly displayed anyway, you can  
use gsub or similar to replace it with a space.  EG:

pdf(file="C:/...", paper="a4", width=8, height=12)
.model <- lm(.model.formula, data=database)
text <- capture.output(summary(.model))
text <- gsub('\t',' ', text)
textplot(, valign="top", halign="left")
dev.off()

As the inclusion of tab characters seems likely to be a problem for  
mony people, I've just added code the gplots::textplot() that will  
replace all occurences of tab with an appropriate number of spaces  
before attempting to compute text heigh or width.  This will be part  
of the next release of gplots, which should show up on CRAN shortly.

-Greg




On Nov 1, 2007, at 2:18PM , Jonas Malmros wrote:

> Dear Gregory,
>
> How can I avoid using tab character when all I want to do is to print
> a model summary on my pdf device using textplot()?
> How do I set the font size? If you mean using cex inside textplot,
> then it does not work. Whether cex is 1 or 0.2 I get the same result,
> exemplified here:
>
> Call:
> lm(formula =...)
> Resuduals:
> ...
>
> Coefficients  Estimate
> (intercept)    1.32
> ...                ...
> ...                ...
>
>                   Std.Error   t-value
> (Intercept)    0.2           0.1
> ...                ...            ...
> ...                ...            ...
>
>                   Pr(>|t|)
> (intercept)     0.01
> ...                ...
> ...                ...
>
> −−−
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> Residual standard error: 1.748...
>
>
> Is there no solution to this problem?
> I am using Vista, R2.6.0 patched, RWinEdt.
>
> textplot(capture.output(summary(.model)), valign="top",  
> halign="left", cex=0.5)
>
> Thanks in advance,
> Jonas
>
> On 11/1/07, Gregory Warnes <gregory.warnes at mac.com> wrote:
>> Hi Jonas,
>>
>> By default, textplot() attempts to automatically select a font size
>> that is 'just big enough, but not too big'.  It does this by a  
>> binary-
>> search approach where it sets a font size, then asks R to compute the
>> actual width of the text to be displayed (without actually displaying
>> it), then increases or decreases the font size appropriately until it
>> finds the largest font that doesn't extend beyond the plot region
>> vertically or horizontally.  It appears that on your system, R
>> doesn't know how wide a tab character is.   This isn't particularly
>> surprising since tab characters vary in width depending on the  
>> context.
>>
>> There are two simple solutions.  First, avoid using characters R
>> can't figure out sizes for (i.e. tab), or manually specify the font
>> size so textplot() doesn't attempt to optimize it.
>>
>> I personally choose the former, avoid tab characters, since the
>> appropriate font size varies greatly by device.
>>
>> -Greg
>>
>> On Oct 31, 2007, at 3:22PM , Jonas Malmros wrote:
>>
>>> Hello,
>>>
>>> I am using textplot function in gplots package to put some model
>>> output inside a PDF file, but it does not seem to work properly with
>>> PDF.
>>>
>>> I am doing follwing:
>>> pdf(file="C:/...", paper="a4", width=8, height=12)
>>> .model <- lm(.model.formula, data=database)
>>> textplot(capture.output(summary(.model)), valign="top",  
>>> halign="left")
>>>
>>> I  am getting these error messages:
>>>
>>> Warning messages:
>>> 1: In FUN(c("C", "a", "l", "l", ":", "l", "m", "(", "f", "o",  
>>> "r",  :
>>>   font width unknown for character 0x9
>>> 2: In strwidth(object, cex = cex) : font width unknown for
>>> character 0x9
>>> 3: In FUN(c("C", "a", "l", "l", ":", "l", "m", "(", "f", "o",  
>>> "r",  :
>>>   font width unknown for character 0x9
>>> 4: In strwidth(object, cex = cex) : font width unknown for
>>> character 0x9
>>> 5: In FUN(c("C", "a", "l", "l", ":", "l", "m", "(", "f", "o",  
>>> "r",  :
>>>   font width unknown for character 0x9
>>> 6: In strwidth(object, cex = cex) : font width unknown for
>>> character 0x9
>>> 7: In text.default(x = xpos, y = ypos, labels = object, adj = c 
>>> (0,  :
>>>   font width unknown for character 0x9
>>> 8: In text.default(x = xpos, y = ypos, labels = object, adj = c 
>>> (0,  :
>>>   font width unknown for character 0x9
>>>
>>> This is a tab character that causes problems, I guess. Is there any
>>> way to solve this?
>>>
>>> Thank you in advance
>>>
>>> --
>>> Jonas Malmros
>>> Stockholm University
>>> Stockholm, Sweden
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-
>>> guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
> -- 
> Jonas Malmros
> Stockholm University
> Stockholm, Sweden
>
> <mime-attachment.txt>



More information about the R-help mailing list