Parse two characters (== 4 == 2 * 2) in ggplot2 annotate

Is there an easy way to parse two identical characters in the same text in ggplot2 annotate or do I need to annotate twice? (i.e. replace :on =the chart below?)

I can build with such an annotate

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)

What gives me this ====

but I cannot have two identical signs, such as

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 understand that my working example is very simple, and you can ask why to replace :with =, but this is a working example.

+4
source share
1 answer
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)

Ed. Plot:

enter image description here

+5

Source: https://habr.com/ru/post/1611662/


All Articles