I've mostly been able to coerce expression() into giving me the mathematical output I've needed for graphs, but I'm flummoxed by this one.
text(-2,.21,expression(P(a <= X)), cex=1.2)
gives me the expected result, but
text(-2,.21,expression(P(a <= X <= b)), cex=1.2)
fails with an arrow pointing to the second \le. Pasting 2 pieces together doesn't work, either, as <= requires both left and right tokens; i.e. this also fails:
text(-2,.21,expression(<= X), cex=1.2)
Any ideas? It's kind of frustrating that there doesn't seem be any documentation on how the expression token parser works short of looking at the source code. The only documentation seems to be a couple of different color versions of this:
http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/plotmath.html
Probability distribution for a discrete random variable. Any value x not explicitly assigned a positive probability is understood to be such that P(X=x) = 0. The function pX(x)= P(X=x) for each x within the range of X is called the probability distribution of X.
To work out the probability that a discrete random variable X takes a particular value x, we need to identify the event (the set of possible outcomes) that corresponds to "X=x". pX(x)=Pr(X=x).
The probability density function (pdf) f(x) of a continuous random variable X is defined as the derivative of the cdf F(x): f(x)=ddxF(x).
Example 1: The table illustrates the probability distribution for the above experiment. Number of Tails (X)012Probability141214. The notation P(X=x) is usually used to represent the probability of a random variable, where the X is random variable and x is one of the values of random variable.
You need to group the operators in plotmath - in otherwords you have to be explicit about the precedence. To do this invisibly, wrap the sub-statements in { }
as in:
R> plot(1:10, type = "n")
R> text(5, 5, expression(P(a <= {X <= b})), cex = 1.2)
Which gives
This is documented (if you know what it means) towards the end of the list of markup plotmath
understands.
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