I'm trying to generate a beautiful legend in R plots. I have a factor=1e-5
, that should appear nicely formatted in the legend. I found a nice function in the package sfsmisc
, that transforms numbers to expressions. To add this expression to my bquote command, it seems that I need to transform itto a call. unfortunately, there are braces added at the end of the string (10^-5()
).
Is there a way to avoid the addition of thoses braces? Or is there even an easier way to transform numbers to plotmaths commands for their use in legends? (without doing it manually)
factor = 1e-5
alpha = 1:10
omega = alpha^2 * factor
plot (
alpha
, omega
, xlab=bquote(alpha)
, ylab=bquote(omega)
, type="b"
)
text = expression()
# standard version
text[1] = as.expression(bquote(alpha%*%.(factor)))
# beautified version (use pretty10exp from sfsmisc package!?)
library("sfsmisc")
pretty = as.call(pretty10exp(factor, drop.1=T))
text[1] = as.expression(bquote(alpha^2%*%.(pretty)))
# add legend
legend("topleft", legend=text, pch=1, lty=1)