Add vertical bar in expression to plot
Asked Answered
C

1

9

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.

Consociate answered 20/3, 2013 at 17:9 Comment(2)
Is there a reason you're unwilling to simply use labels = "E(X|Y)"?Foamy
Yes, I need to to add superscripts and indices later in more complicated expressions.Consociate
A
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

Aftershaft answered 20/3, 2013 at 17:26 Comment(3)
@Foamy I added your version which produces slightly different result.Aftershaft
I think yours is more correct, typographically, but only a true LaTeX nerd could settle this definitively.Foamy
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?Consociate

© 2022 - 2024 — McMap. All rights reserved.