4

I have a problem inserting a vertical line in a mathematical annotation. I have search through the annotation symbols without luck.

I would like to put a mathematical annotation containing conditional probability sign (|) in the x-label of a plot. What I would like is the expression p(x_j | o_i) where "j" and "i" are subscripts.

I have the following construction

plot(1:10, xlab = expression( paste("Likelihood, p" * (y[i] %up% o[j])) ))

and I wold like to substitute the arrow with a vertical line. Any help or guidance is greatly appreciated.

plannapus
  • 18,529
  • 4
  • 72
  • 94
Sisse
  • 291
  • 1
  • 4
  • 14

2 Answers2

7

This gets you "there" (for some definition of "there"):

plot(1:10, xlab = expression("Likelihood, p" * (y[i] ~ "|" ~ o[j])))

plotmath axis label

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
4

This is not intended to be the answer for the OP. It seems that many people enjoy playing with the plotmath hacks in R, but the tikzDevice package has given us a decent solution for this type of problems: you can write native LaTeX expressions in R plots. Then knitr makes the learning curve less steep. Below is what you can achieve with R (much better quality than plotmath):

tikz graphics from tikzDevice and kntir

The full Rnw source (save it as, say, test.Rnw):

\documentclass{article}
\usepackage{alltt}
\begin{document}
<<likelihood, fig.width=4, fig.height=2.5, dev='tikz'>>=
par(mar = c(4.5, 4, .1, .1))
plot(1:10, xlab = 'Likelihood, $p(y_{i}|o_{j})$')
@
\end{document}

Then

install.packages(c('knitr', 'tikzDevice'))
library(knitr)
knit('test.Rnw')

You will have a PDF file named figure/likelihood.pdf which is the plot above. See Figure 9 in the graphics manual and Page 7 in the main manual of the knitr package for more examples. LaTeX is required to compile tikz to PDF.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419