如何在ggplot中为geom_text()添加字母数字和希腊字符?

drb*_*sen 12 latex r ggplot2

我正在尝试创建一个使用包含字母数字和希腊字符的文本进行注释的图表.如果我想添加希腊字符,我可以使用:

qplot(x, y) + geom_text(aes(2, 2, label="rho"), parse=TRUE)
Run Code Online (Sandbox Code Playgroud)

如何用"ρ和其他文本"注释图?我想做这样的事情:

qplot(x, y) + geom_text(aes(2, 2, label="rho and some other text"), parse=TRUE)
Run Code Online (Sandbox Code Playgroud)

当我尝试上面的代码时,我收到此错误:

Error in parse(text = lab) : <text>:1:5: unexpected symbol
1: rho and
       ^
Run Code Online (Sandbox Code Playgroud)

我也很感激任何解决方案,允许我将LaTeX geom_text()用于更复杂的用例.

Ben*_*ker 15

一种解决方案:替代倾斜~空间.

d <- data.frame(x=1:3,y=1:3)
qplot(x, y, data=d) + geom_text(aes(2, 2,
              label="rho~and~some~other~text"), parse=TRUE)
Run Code Online (Sandbox Code Playgroud)

*~作品,如果你想并列空格.

对于完整的LaTeX解决方案,我想你想看看这个tikzDevice包,可能与knitr(块上新的最酷的包)一起使用; 例如,见http://yihui.name/knitr/demo/graphics/