解析ggplot2的注释中的两个符号(==4==2*2) [英] parse two signs (==4==2*2) in ggplot2's annotate
本文介绍了解析ggplot2的注释中的两个符号(==4==2*2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以在 ggplot2 的注释中解析同一文本中的两个等号,还是必须注释两次?(即将下图中的 :
替换为 =
?)
Is there a simply way to parse two equal signs in the same text in ggplot2's annotate or do I have to annotate twice? (i.e. replace :
by =
in the plot below?)
我可以用这样的注释绘图
I can plot with annotate like this
require(ggplot2)
f <- data.frame(x = c(0, 1/1.1), y = c(1/.9, 0))
c <- ggplot(f, aes(x, y))
c + stat_smooth(method = "lm", se=F)
+ annotate("text", x=.6,y=.75, label=(paste0("slope:","frac(1, f[1])==",
coef(lm(f$y ~ f$x))[2])), parse=TRUE)
这给了我这个,
但是我不能有两个这样的等号,
but I cannot have two equal signs like this,
f <- data.frame(x = c(0, 1/1.1), y = c(1/.9, 0))
c <- ggplot(f, aes(x, y))
c + stat_smooth(method = "lm", se=F) + annotate("text", x=.6,y=.75,
label=(paste0("slope==","frac(1, f[1])==", coef(lm(f$y ~ f$x))[2])), parse=TRUE)
我收到此错误.
Error in parse(text = lab) : <text>:1:23: unexpected '=='
1: slope==frac(1, f[1])==
^
在我的实际情况中,我有几个分数,我意识到我的工作示例非常简单,人们可能会问为什么将 :
替换为 =
,但这是一个工作示例.
In my real case I have several fractions, I realize that my working example is very simply and one might ask why replace :
by =
, but it's a working example.
推荐答案
f <- data.frame(x = c(0, 1/1.1), y = c(1/.9, 0))
c <- ggplot(f, aes(x, y))
c <- c + stat_smooth(method = "lm", se=F) + annotate("text", x=.6,y=.75, label=(paste0("slope==~frac(1,f[1])==", coef(lm(f$y ~ f$x))[2])), parse=TRUE)
plot(c)
已编辑.剧情是:
这篇关于解析ggplot2的注释中的两个符号(==4==2*2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文