如何在 ggplot 中将字母数字和希腊字符添加到 geom_text()? [英] How can I add alpha-numeric AND greek characters to geom_text() in ggplot?

查看:17
本文介绍了如何在 ggplot 中将字母数字和希腊字符添加到 geom_text()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a plot that is annotated with text that contains both alpha-numeric and greek characters. If I want to add just greek characters I can use:

qplot(x, y) + geom_text(aes(2, 2, label="rho"), parse=TRUE)

如何用ρ and some other text"注释情节?我想做这样的事情:

How can I annotate a plot with "ρ and some other text"? I would like to do something like this:

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

当我尝试上面的代码时,我得到了这个错误:

When I try the above code, I get this error:

Error in parse(text = lab) : <text>:1:5: unexpected symbol
1: rho and
       ^

如果有任何解决方案可以让我在 geom_text() 中使用 LaTeX 来解决未来更复杂的用例,我也将不胜感激.

I would also appreciate any solution that would allow me to use LaTeX in geom_text() for more complex use cases in the future.

推荐答案

一种解决方案:用波浪线 ~ 代替空格.

One solution: substitute tildes ~ for spaces.

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)

* 代替 ~ 如果您想并列 空格,则可以.

Substituting * for ~ works if you want to juxtapose without spaces.

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

For the complete LaTeX solution I think you want to have a look at the tikzDevice package, possibly used in conjunction with knitr (the new coolest package on the block); e.g. see http://yihui.name/knitr/demo/graphics/

这篇关于如何在 ggplot 中将字母数字和希腊字符添加到 geom_text()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆