如何在ggplot2中使用希腊符号? [英] How to use Greek symbols in ggplot2?
问题描述
我的类别需要用希腊字母命名。我正在使用 ggplot2
,并且它与数据一起工作得很好。不幸的是,我无法弄清楚如何将这些希腊符号放在x轴上(在刻度线上),并让它们出现在图例中。有没有办法做到这一点?
更新:
我看了链接,但是,没有描述完成我想要做的事情的好方法。
以下是链接到一个出色的wiki,它解释了如何在ggplot2中放置希腊符号。总之,以下是你如何获得希腊符号
- 文字标签:使用
parse = T
内部geom_text
或注释
。 - 轴标签:使用
表达式(alpha)
来获取希腊字母。 方面标签:在facet
中使用labeller = label_parsed
。 - 图例标签:在图例标签中使用
bquote(alpha ==。(value))
。
您可以在链接
编辑中看到这些选项的详细用法。沿着刻度线使用希腊符号的目标可以实现如下:
require(ggplot2);
数据(提示);
p0 = qplot(sex,data = tips,geom ='bar');
p1 = p0 + scale_x_discrete(labels = c('Female'= expression(alpha),
'Male'= expression(beta)));
print(p1);
有关在执行此操作时可用的各种符号以及如何使用它们的完整文档,请参阅?plotmath
。
My categories need to be named with Greek letters. I am using ggplot2
, and it works beautifully with the data. Unfortunately I cannot figure out how to put those greek symbols on the x axis (at the tick marks) and also make them appear in the legend. Is there any way to do it?
UPDATE: I had a look at the link, however, there is no good method described to accomplish what I want to do.
Here is a link to an excellent wiki that explains how to put greek symbols in ggplot2. In summary, here is what you do to obtain greek symbols
- Text Labels: Use
parse = T
insidegeom_text
orannotate
. - Axis Labels: Use
expression(alpha)
to get greek alpha. - Facet Labels: Use
labeller = label_parsed
insidefacet
. - Legend Labels: Use
bquote(alpha == .(value))
in legend label.
You can see detailed usage of these options in the link
EDIT. The objective of using greek symbols along the tick marks can be achieved as follows
require(ggplot2);
data(tips);
p0 = qplot(sex, data = tips, geom = 'bar');
p1 = p0 + scale_x_discrete(labels = c('Female' = expression(alpha),
'Male' = expression(beta)));
print(p1);
For complete documentation on the various symbols that are available when doing this and how to use them, see ?plotmath
.
这篇关于如何在ggplot2中使用希腊符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!