Eri*_*ail 5 plot parsing annotations r ggplot2
是否有一种简单的方法可以在ggplot2的注释中解析同一文本中的两个等号或者我是否需要注释两次?(如更换:由=在图下方?)
我可以用这样的注释进行绘图
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)
Run Code Online (Sandbox Code Playgroud)
但我不能有这样两个相同的标志,
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)
Run Code Online (Sandbox Code Playgroud)
我收到这个错误.
Error in parse(text = lab) : <text>:1:23: unexpected '=='
1: slope==frac(1, f[1])==
^
Run Code Online (Sandbox Code Playgroud)
在我的现实情况下,我有几个分数,我意识到,我的工作的例子很简单,有人可能会问,为什么更换:的=,但它是一个工作的例子.
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)
Run Code Online (Sandbox Code Playgroud)
编辑.情节是: