[R] annotation problems (conditional text())

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Nov 20 17:43:37 CET 2004


Johannes Graumann wrote:

> Hello,
> 
> I'm trying to annotate my plots nicely and am running into trouble.
> This example contains two problems:
> a) the 'text()' arguments do not show the conditional behavior I'm
> trying to give them. I try to test for the intercept of my regression
> and reformat the output accordingly ('+ intercept' in the >= 0 case and
> '- sqrt(intercept^2)' in the other case), which doesn't work this way.
> b) my pasted substitute commands yield jolted output, which overwrites
> itself ...
> 
> Can anyone give this newbie a nudge into the right direction?

1. Multi-line mathematical annotation is not supported. You have to add 
them line by line.

2. You want to use a construct such as
   if(m >= 0){
     # code for text 1
   } else{
     # code for text 2
   }
rather than the one you speicfied below, which evaluates both text() 
calls if m > 0.

Uwe Ligges


> Thanks, Joh
> 
> if(m >= 0){
>   text(
>     4,0.19,
>     cex=0.75,
>     adj=0,
>     paste(
>       substitute(
>         y == m*x+b,
>         list(
>           m=round(m,digits=5),
>           b=round(b,digits=5)
>         )
>       ),
>       "\n",
>       substitute(
>         R^2==rsquared,
>         list(
>           rsquared=round(summary(fit)$r.squared,digits=3)
>         )
>       )
>     )
>   );
>   text(
>     4,0.19,
>     cex=0.75,
>     adj=0,
>     paste(
>       substitute(
>         y == m*x-b,
>         list(
>           m=round(m,digits=5),
>           b=round(sqrt(b^2),digits=5)
>         )
>       ),
>       "\n",
>       substitute(
>         R^2==rsquared,
>         list(
>           rsquared=round(summary(fit)$r.squared,digits=3)
>         )
>       )
>     )
>   )
> }
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list