tomka
tomka

Reputation: 2638

Add vertical bar in expression to plot

I'd like to add an expression to a plot, in which a conditional term appears, such as E(Y|X). Using for example:

plot(x=c(.5),ylim=c(0,1),xlim=c(0,2))
text(x=1,y=.5,labels=expression(E(X|Y)),pos=1)

does not do it, but it produces E(|(X,Y)). Obviously I do not know how to get the vertical bar into the expression properly - can somebody help? Thanks.

Upvotes: 9

Views: 3864

Answers (1)

agstudy
agstudy

Reputation: 121568

plot(x=c(.5),ylim=c(0,1),xlim=c(0,2))
expr = expression("E" * (X ~ "|" ~ Y))
text(x=1,y=.5,labels=expr,pos=1,cex=4)

EDIT

@joran proposes a different version ( there are less spaces in this one)

 expr1 = expression(E(X*"|"*Y))
 text(x=1,y=.8,labels=expr2,pos=1,cex=4)

enter image description here

Upvotes: 14

Related Questions