Extended legend in R: Story

This is the next question on this question: How to create a new line in the `bquote` expression used with` text`?

But now I have it in legend, and it seems to change the situation.

I tried the following:

test<-c(10:1)
dummy1<-0.004323423
dummy2<-0.054
dummy3<-0.032
plot(test,c(1:10))
legend("topright", 
 legend=c(bquote(Qua_0,99^normal == .(round(dummy1,4))),bquote(Qua_0,95^normal == .(round(dummy2,4))),bquote(Qua_0,99^t == .(round(dummy3,4)))),
 bty = "n",lwd=2, cex=1, col=c("red","black","darkgreen"), lty=c(1,3,5))

So I want to have

  • The expression is correct, so the 0.95 index is spelled correctly, as well as the degree of match

  • linebreak after equal sign

  • colored text is the same as lign, so the first will be in red

I tried to respond to existing messages, but I did not understand, atop also does not work.

+5
source share
2 answers

substitute, . , as.expression, , atop . legend:

v <- c(
 as.expression(substitute(atop(Qua[0.99]^normal == "", dummy), list(dummy=round(dummy1,4)))),
 as.expression(substitute(atop(Qua[0.95]^normal == "", dummy), list(dummy=round(dummy2,4)))),
 as.expression(substitute(atop(Qua[0.99]^t == "", dummy), list(dummy=round(dummy3,4))))
)
cols <- c("red","black","darkgreen")
legend("topright", legend=v, bty = "n",lwd=2, cex=1, col=cols, text.col=cols, lty=c(1,3,5))

text.col. enter image description here

bquote, substitute:

 v <- c(
  as.expression(bquote(atop(Qua[0.99]^normal == "", .(round(dummy1,4))))),
  as.expression(bquote(atop(Qua[0.95]^normal == "", .(round(dummy2,4))))),
  as.expression(bquote(atop(Qua[0.99]^t == "", .(round(dummy3,4)))))
 )

0.99 , bold :

v <- c(
 as.expression(substitute(atop(Qua[bold(0.99)]^bold(normal) == "", dummy), list(dummy=round(dummy1,4)))),
 as.expression(substitute(atop(Qua[bold(0.95)]^bold(normal) == "", dummy), list(dummy=round(dummy2,4)))),
 as.expression(substitute(atop(Qua[bold(0.99)]^bold(t) == "", dummy), list(dummy=round(dummy3,4))))
)

0.99 : enter image description here

textstyle:

v <- c(
 as.expression(substitute(atop(Qua[textstyle(0.99)]^textstyle(normal) == "", dummy), list(dummy=round(dummy1,4)))),
 as.expression(substitute(atop(Qua[textstyle(0.95)]^textstyle(normal) == "", dummy), list(dummy=round(dummy2,4)))),
 as.expression(substitute(atop(Qua[textstyle(0.99)]^textstyle(t) == "", dummy), list(dummy=round(dummy3,4))))
)

: enter image description here

+5

, - 3 - c - , . , sapply as.expression , " ".

plotmath atop, "linebreak"; , .

0,95, , , 0.95, * ",", 0 95. , , . , . , , [0,99] [0.99], .

bquote(atop(foo_0.99^normal ==, .round(bar, 4)))

:

> bquote(atop(foo_0.99^normal ==, .round(bar, 4)))
Error: unexpected ',' in "bquote(atop(foo_0.99^normal ==,"

, /t 215 > function/operator. == ( !), -, , ==. phantom(), , ( ). == "", "" phantom().

, , text.col.

( ):

test <- 10:1
dummy1 <- 0.004323423
dummy2 <- 0.054
dummy3 <- 0.032
plot(test, 1:10)

## list of expressions
exprs <-
  list(bquote(atop(Qua_0 * "," * 99^normal == phantom(), .(round(dummy1, 4)))),
       bquote(atop(Qua_0 * "," * 95^normal == phantom(), .(round(dummy2, 4)))),
       bquote(atop(Qua_0 * "," * 99^t == phantom(), .(round(dummy3, 4)))))
## fudge to get them as an expression vector
exprs <- sapply(exprs, as.expression)

cols <- c("red", "black", "darkgreen")
legend("topright", legend = exprs, bty = "n", lwd = 2, cex = 1, col = cols,
       lty=c(1,3,5), text.col = cols)

, LaTeX _ . plotmath [ ]. , - , . , atop, . , y.intersp legend. 2 .

, , :

plot(test, 1:10)

## list of expressions
exprs <-
  list(bquote(atop(Qua[0.99]^normal == phantom(), .(round(dummy1, 4)))),
       bquote(atop(Qua[0.95]^normal == phantom(), .(round(dummy2, 4)))),
       bquote(atop(Qua[0.99]^t == phantom(), .(round(dummy3, 4)))))
## fudge to get them as an expression vector
exprs <- sapply(exprs, as.expression)

cols <- c("red", "black", "darkgreen")
legend("topright", legend = exprs, bty = "n", lwd = 2, cex = 1, col = cols,
       lty=c(1,3,5), text.col = cols, y.intersp = 2)

:

enter image description here

+5

All Articles