在 ggplot2 的注释中解析两个符号 (==4==2*2)
parse two signs (==4==2*2) in ggplot2's annotate
在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)
这给了我这个,
但是我不能像这样有两个等号,
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])==
^
在我的真实案例中,我有几个分数,我意识到我的工作示例非常简单,有人可能会问为什么用 =
替换 :
,但这是一个工作示例。
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的注释中,有没有一种简单的方法来解析同一文本中的两个等号,或者我必须注释两次? (即在下图中用 =
替换 :
?)
我可以像这样用注释绘图
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)
这给了我这个,
但是我不能像这样有两个等号,
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])==
^
在我的真实案例中,我有几个分数,我意识到我的工作示例非常简单,有人可能会问为什么用 =
替换 :
,但这是一个工作示例。
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)
已编辑。情节是: