8

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.

tomka
  • 2,516
  • 7
  • 31
  • 45

1 Answers1

14
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

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • @joran I added your version which produces slightly different result. – agstudy Mar 20 '13 at 17:37
  • 2
    I think yours is more correct, typographically, but only a true LaTeX nerd could settle this definitively. – joran Mar 20 '13 at 17:38
  • I am totally happy with these solutions for my purpose, but isn't it true that the vertical bar in both solutions is located a bit too low? Shouldn't it overarch the top of X and Y? – tomka Mar 22 '13 at 10:46