title: How to add Latex code in ggplot2 legend labels?
body: <p>Consider the following example:</p>
  
  <pre><code>p &lt;- ggplot(data = data.frame(A=c(1,2,3,4,5,6,7,8),B=c(4,1,2,1,3,2,4,1),C=c("A","B","A","B","A","B","A","B")))
  p &lt;- p + geom_line(aes(x = A, y = B,color = C))
  </code></pre>
  
  <p>I would like to change the labels in the legend from "A" and "B" to Latex formulae, say "$A^h_{t-k}$" and "$B^h_{t-k}$", respectively.</p>
  
  <p>Apparently, according to the answers <a href="https://stackoverflow.com/questions/1395105/getting-latex-into-r-plots">here</a>, ways to achieve this exist. However, I am really struggling to get it to work. Could somebody break it down for me?</p>