【发布时间】:2015-10-14 18:25:37
【问题描述】:
是否有一种简单的方法可以在 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])==
^
在我的真实案例中,我有几个分数,我意识到我的工作示例非常简单,有人可能会问为什么用= 替换:,但这是一个工作示例。
【问题讨论】:
标签: r parsing plot ggplot2 annotations