通过 geom_text 在 R 中将小于号“<”添加到 ggplot
Add less than symbol, "<", to a ggplot via geom_text in R
简短版本:我如何让这个人为的代码绘制一个正确的希腊字母 beta 字符和标签字符串的其余部分,以及 space 和更少比字符和数字格式化为键入?
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”参数,该字符串效果很好,但不会给我真正的希腊语测试版。如果我把它留在里面,一切都会崩溃。
长版(以及为什么我找不到重复的):我终于在 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? 中发现了,我认为这是我的答案,但修复了"space" 导致额外的括号突然出现,“=”被逗号替换,并且我之前格式化的所有文本数字都丢失了格式。
关于使用 parse 参数的指南以及如何理解在我看来完全不直观的内容的 link 对我非常有帮助,可能未来的 R 用户也会在这里结束。多次搜索无果。
应该这样做:
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'")
就是把标签用单引号分割到空格的一边,用*
连接两个标签位。您还需要 ==
表示等于。
简短版本:我如何让这个人为的代码绘制一个正确的希腊字母 beta 字符和标签字符串的其余部分,以及 space 和更少比字符和数字格式化为键入?
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”参数,该字符串效果很好,但不会给我真正的希腊语测试版。如果我把它留在里面,一切都会崩溃。
长版(以及为什么我找不到重复的):我终于在 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? 中发现了,我认为这是我的答案,但修复了"space" 导致额外的括号突然出现,“=”被逗号替换,并且我之前格式化的所有文本数字都丢失了格式。
关于使用 parse 参数的指南以及如何理解在我看来完全不直观的内容的 link 对我非常有帮助,可能未来的 R 用户也会在这里结束。多次搜索无果。
应该这样做:
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'")
就是把标签用单引号分割到空格的一边,用*
连接两个标签位。您还需要 ==
表示等于。