I've searched all over and can't find the code for having a conditional sign as in
p(a|b)
The code (generic R code, not ggplot) I'm using is
ylab = bquote(Pr( Y == y | theta == .(mytheta) , n == .(n)))
What this gives me for a label is
Pr(|(Y=y,theta=0.2), n=10)
Where the theta is a proper Greek symbol, mytheta is 0.2, and n is 10. So all that's not working is the conditional sign. It looks to me like R is taking the | for an or...
I haven't tried ggplot yet, but would like to get this working in plain R first.
Thanks for your help.
I always just use expression
. I haven't used bquote
before.
Sorry, I did a bunch of these and obviously exported the wrong one. Use paste
not paste0
.
plot(rnorm(100), rnorm(100), ylab= expression(paste("P(Y| ", theta," )")))
I thought it was pretty interesting to see that 'pipe' (vs. 'OR') get parsed into Polish notation. The conditional-bar can be accessed with the Symbol font using the methods described in ?plotmath
and ?points
plot(1,1, main=bquote(Pr( Y == y ~ symbol("\275") ~ theta == .(mytheta) , n == .(n))))
(I did try making a SPECIAL user-defined function using %|%
as the missing conditional symbol, but failed.)
To your comment-question asking for an illustration (actually two versions of how to use substitute
in an equivalent manner:
mytheta = 0.2
plot(rnorm(100), rnorm(100), ylab= substitute(P(Y~"|"~ mytheta ), list(mytheta=mytheta)) )
plot(rnorm(100), rnorm(100), ylab= substitute(P(Y~"|"~ theta == mytheta ),
list(mytheta=mytheta)) )
# Second version prints greek-theta == value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With