我有以下代码:
require(extrafont)
xaxis <- seq(0,1,by=0.01)
#set the functions here
aij <- sqrt(1 - (1-xaxis)**1.02)
bij <- 1 - (1 - xaxis)**1.50
cij<-aij-bij
pdf("MyPlot.pdf",family="Times New Roman")
par(mfrow=c(1, 1), mar=c(5, 5, 1, 5))
plot(xaxis,aij,type="l", col="black",lty=1,ylim=c(0,1.3))
lines(xaxis,bij,type="l",col="black",lty=2)
par(new=TRUE)
plot(xaxis,cij,,type="l",col="black",lty=4,xaxt="n",yaxt="n",xlab="",ylab="")
grid(nx = 10, ny = 10)
xlab("Size ratio")
ylab("Values of the functions")
axis(4)
mtext("Difference", side=4,line=3)
legend(x='topright',col=c("black","black"),lty=c(1,2,3),legend=c("aij","bij","Difference"),bty="n")
dev.off()
我希望图例在LaTeX输出中显示为$a_{ij}$
和$b_{ij}$
。我怎么做?
答案 0 :(得分:3)
对于图例中的下标,请使用函数expression
,并在&#34; []&#34;之间使用下标的术语。 (方括号):
legend(x='topright',col=c("black","black"),lty=c(1,2,3),legend=c(expression(a[ij]),expression(b[ij]),"Difference"),bty="n")
如果您希望它以斜体显示,因为它在Latex数学模式中自动发生,请在方括号内使用italic
:
legend(x='topright',col=c("black","black"),lty=c(1,2,3),legend=c(expression(a[italic(ij)]),expression(b[italic(ij)]),"Difference"),bty="n")