[R] plotmath and logical operators?
Gabor Grothendieck
ggrothend|eck @end|ng |rom gm@||@com
Tue Aug 21 14:53:15 CEST 2018
Try this:
plot(1)
tmp <- x >= 3 ~ "&" ~ y <= 3
mtext(tmp)
On Mon, Aug 20, 2018 at 5:00 PM MacQueen, Don via R-help
<r-help using r-project.org> wrote:
>
> I would like to use plotmath to annotate a plot with an expression that includes a logical operator.
>
> ## works well
> tmp <- expression(x >= 3)
> plot(1)
> mtext(tmp)
>
> ## not so well
> tmp <- expression(x >= 3 & y <= 3)
> plot(1)
> mtext(tmp)
>
> Although the text that's displayed makes sense, it won't be obvious to my non-mathematical audience.
>
> I'd appreciate suggestions.
>
>
> I've found a work-around that gets the annotation to look right
> tmpw <- expression(paste( x >= 3, " & ", y <= 3) )
> plot(1)
> mtext(tmpw)
>
>
> But it breaks my original purpose, illustrated by this example:
>
> df <- data.frame(x=1:5, y=1:5)
> tmp <- expression(x >= 3 & y <= 3)
> tmpw <- expression(paste( x >= 3, " & ", y <= 3) )
> with(df, eval(tmp))
> [1] FALSE FALSE TRUE FALSE FALSE
> with(df, eval(tmpw))
> [1] "FALSE & TRUE" "FALSE & TRUE" "TRUE & TRUE" "TRUE & FALSE" "TRUE & FALSE"
>
> Thanks
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list