在R中通过geom_text将小于符号“<”添加到ggplot [英] Add less than symbol, "<", to a ggplot via geom_text in R

查看:177
本文介绍了在R中通过geom_text将小于符号“<”添加到ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短版:我怎样才能让这个人为的代码作为一个适当的希腊贝塔字符和标签字符串的其余部分,空格和小于字符以及格式化为键入的数字?

  library(ggplot2)
df <-data.frame(a = 1:15,b = 6 :20)
ggplot(data = df,aes(x = a,y = b))+ geom_point()+
geom_text(x = 5,y = 4,label =beta = 1.00 p < ; 0.0001,parse = TRUE)

如果省略,parse = TRUE该字符串很好,但不会给我一个真正的希腊测试版。如果我把它放进去,所有的地狱都会破裂。






长版我找不到重复的):我终于在中发现如何使用希腊符号在ggplot2?中,希腊字符放在ggplot上的方法取决于你把它们放在哪里。由于我使用geom_text强制将文本字符串放到图的主体上,所以我尝试使用表达式(测试版)失败,最近我开始使用上面提到的parse参数。我遇到了如何我可以在ggplot?中添加字母数字和希腊字符到geom_text(),我认为这是我的答案,但修复空格会导致额外的括号弹出,=替换为逗号,并且对于我之前格式化过的所有文本数字,格式化丢失。



使用parse参数的指南的链接,以及如何理解对我来说是什么完全不直观的会对我很有帮助,并且可能会有未来的R用户在这里结束。许多搜索都没有结果。

解决方案



<$ (x = a,y = b))+ geom_point()
g +注释(text,x = 5, y = 4,parse = TRUE,label =beta == 1.00 *'p <0.0001')

这是一个用单引号将标签分割到空白区域并用 * 连接两个标签位的问题。您还需要 == 等于。




The short version: How would I make this contrived code plot a proper greek beta character AND the rest of the label string, with the space and the less than character and the numbers formatted as typed?

library("ggplot2")
df<-data.frame(a=1:15,b=6:20)
ggplot(data=df, aes(x=a,y=b)) + geom_point() +
       geom_text(x=5,y=4,label="beta=1.00 p<0.0001", parse=TRUE)

If I leave out the ", parse=TRUE" argument, the string works great, but won't give me a real greek beta. If I leave it in, all hell breaks loose.


The long version (and why I can't find a duplicate): I finally discovered in How to use Greek symbols in ggplot2? that methods for placing greek characters on a ggplot depends upon where you're putting them. Since I am using geom_text to force strings of text onto the body of the plot, my attempts to use expression(beta) have failed and I recently started using the parse argument mentioned above. I came across How can I add alpha-numeric AND greek characters to geom_text() in ggplot?, which I thought was my answer, but fixing the "space" resulted in extra parentheses popping in, "=" replaced by a comma, and loss of formatting for all of my previously formatted text numerics.

A link to a guide for using the parse argument, and how to make sense of what seems to me to be completely unintuitive would be very helpful to me, and probably future R users ending up here. Many searches have been fruitless.

解决方案

This should do it:

g <- ggplot(data=df, aes(x=a,y=b)) + geom_point()
g + annotate("text", x=5,y=4,parse=TRUE, label="beta==1.00 * ' p<0.0001'")

It's a matter of splitting the label with single quotes to the side of the whitespace and connecting two label bits with *. You also need the == for equals to.

这篇关于在R中通过geom_text将小于符号“&lt;”添加到ggplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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