在GGPLOT2的注释解析两个标志(== == 4 2 * 2) [英] parse two signs (==4==2*2) in ggplot2's annotate
本文介绍了在GGPLOT2的注释解析两个标志(== == 4 2 * 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法来分析在同一文本中两个等号在GGPLOT2的注释或者我必须标注的两倍? (即替换:
按 =
如下图)
我可以用这样的注释绘制
要求(GGPLOT2)
F&下; - data.frame(X = C(0,1 / 1.1),Y = C(1 / 0.9,0))
C< - ggplot(F,AES(X,Y))
C + stat_smooth(方法=LM,SE = F)
注释+(文字,X =。6,Y = .75标签=(paste0(坡,压裂(1,F [1])==
系数(LM(F $ Y〜F $ X))[2])),解析= TRUE)
但我不能有两个等号这样,
F< - data.frame(X = C(0,1 / 1.1),Y = C(1 / .9 0))
C< - ggplot(F,AES(X,Y))
C + stat_smooth(方法=LM,SE = F)+注释(文字,X =。6,Y = .75
标签=(paste0(坡==,压裂(1中,f [1])==,系数(流明(F $ Y〜F $ x)的)[2])),解析= TRUE)
我得到这个错误。
错误解析(文=实验室):其中,文本> 1:23:意外'=='
1:坡==压裂(1中,f [1])==
^
在我有几个部分我的真实情况,我意识到我的工作的例子很简单,有人可能会问,为什么替换:
按 =
,但它是一个工作的例子。
解决方案
F< - data.frame(X = C(0,1 / 1.1),Y = C(1 /.9,0))
C< - ggplot(F,AES(X,Y))
C< - C + stat_smooth(方法=LM,SE = F)+注释(文字,X =。6,Y = .75标签=(paste0(坡==〜压裂(1,F [1])==,系数(流明(F $ Y〜F $ x)的)[2])),解析= TRUE)图(三)
编辑。情节是:
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)
Which gives me this,
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)
I get this error.
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)
Edited. Plot is:
这篇关于在GGPLOT2的注释解析两个标志(== == 4 2 * 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文