Legend using bquote together with a vector variable
Asked Answered
M

1

3

I want to plot a legend with bquote containing 4 rows (kappa=0.5, kappa=1, kappa=1.5, kappa=5).

Fot example:

kappa_var <- c(0.5, 1.0, 1.5, 5.0)

plot(1000, type="n", xlab="x", ylab= expression(paste("f(x;",kappa,",",sigma,")",sep="")), 
     xlim=c(0, 5), ylim=c(0, 6))

legend("topleft",legend=do.call( 'expression', list( bquote( kappa == .(kappa_var)))))

However I can only manage that bquote is expressing the first entry of kappa_var and not all of them

Mosqueda answered 22/9, 2019 at 11:40 Comment(0)
S
4

Try creating a vector of expressions with as.expression from a list of bquote labels:

legend("topleft", legend = as.expression(sapply(kappa_var, function(var) bquote(kappa == .(var)))))
Sadick answered 22/9, 2019 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.