我为多个数据集生成了一个图。每个数据集都应该有自己的图例,其中可能包含希腊字母、绘图符号或子和上标。我想循环生成图例文本。
如果只有一个图例文本,Bquote 可以正常工作。如果我尝试添加额外的图例文本,plotmath-commads 会丢失,...
x <- 0:10
y1 = x * x
y2 = x * 10
plot (1,1, type="n", xlab=bquote(Omega), ylab="Y", las=1, xlim=range(x), ylim=range(y1, y2))
lines(x, y1, col=1, pch=1, type="b")
lines(x, y2, col=2, pch=2, type="b")
# generate legend texts (in a loop)
legend_texts = c(
bquote(Omega^2)
, bquote(Omega%*%10)
)
# Using a single bquote works fine:
#legend_texts = bquote(Omega^2)
#legend_texts = bquote(Omega%*%10)
legend(
"topleft"
, legend = legend_texts
, col = c(1:2)
, pch = c(1:2)
, lty = 1
)