问题描述
x = seq(0.1,5,by=0.05)
y = x * log(x)
plot(x,y,col="darkblue",pch=".")
lines(x,x,col="darkred",pch="-")
points(y,col="darkgreen",pch=".")
legend("topleft",legend=c("y = f(x)","y = x",expression(y = f^(-1) (x))),col = c("darkblue","darkred","darkgreen"),text.col = c("darkblue",pch = rep("-",3))
我试图将图例添加到 f(x)及其反函数中。以上是代码及其产生的内容,下面是图例应的外观。我该怎么做?
解决方法
您需要在表达式中使用双等于:
expression(y == {f^{-1}} (x))
来自?plotmath
,
‘x == y’:x等于y
要防止(x)
上标,可以使用{}
对表达式的较早部分进行分组/保护