如何在ggplot2中使用希腊符号? [英] How to use Greek symbols in ggplot2?

查看:258
本文介绍了如何在ggplot2中使用希腊符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类别需要用希腊字母命名。我正在使用 ggplot2 ,并且它与数据一起工作得很好。不幸的是,我无法弄清楚如何将这些希腊符号放在x轴上(在刻度线上),并让它们出现在图例中。有没有办法做到这一点?



更新:
我看了链接,但是,没有描述完成我想要做的事情的好方法。

解决方案

以下是链接到一个出色的wiki,它解释了如何在ggplot2中放置希腊符号。总之,以下是你如何获得希腊符号


  1. 文字标签:使用 parse = T 内部 geom_text 注释

  2. 轴标签:使用表达式(alpha)来获取希腊字母。 方面标签:在 facet 中使用 labeller = label_parsed

  3. 图例标签:在图例标签中使用 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

  1. Text Labels: Use parse = T inside geom_text or annotate.
  2. Axis Labels: Use expression(alpha) to get greek alpha.
  3. Facet Labels: Use labeller = label_parsed inside facet.
  4. 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屋!

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