postscript文件中的多图

时间:2017-07-03 17:18:30

标签: r graph postscript

我在一个窗口中创建两个图表,

(1)当我显示它有效但当我尝试保存为postscript文件时,它只保存一个图形而不是第二个部分。我附上代码和图像(显示我想看到的和eps文件)。

(2)如何在轴标签中显示pi符号?

(3)如何在图例中显示下标,例如$ y_1 $,$ y_2 $(如tex)

I would like to see like this in eps file

rm(list=ls())
par(mfrow=c(2,1))
par(mar = c(4,4.5,1,1))
postscript(file="Test.eps", onefile = TRUE, horizontal = FALSE)

x <- seq(-pi, pi, by=0.1)
y1<-abs(cos(x)); y2<-abs(sin(x))
m<-cbind(x,y1,y2,y1+y2,abs(y1-y2))

matplot(m[,1],(m[,c(2,3,4)]), type="l", lty=c(1,2,3,4),ylim=c(0,max(unlist(m[,2:5]))), xaxt="n",xlab="Time",ylab="Y",lwd=2,col=c("black","black","black","black"))
axis(1,c(-pi,-pi/2,0,pi,pi/2))
legend("topright", c("y1","y2","y1+y2","y1-y2"),lty=c(1,2,3,4),lwd=2,col="black")

matplot(m[,1],(m[,c(2,3,5)]), type="l", lty=c(1,2,3,4),ylim=c(0,max(unlist(m[,2:5]))),
       xaxt="n",xlab="Time",ylab="Y",lwd=2,col=c("black","black","black","black"))
axis(1,c(-pi,-pi/2,0,pi,pi/2))
legend("topright", c("y1","y2","y1+y2","y1-y2"),lty=c(1,2,3,4),lwd=2,col="black")

par(mfrow=c(1,1))
graphics.off()

我无法上传eps文件,但这并未显示最后一个情节。

1 个答案:

答案 0 :(得分:0)

请参阅上面的评论以获得解释。这是工作代码
enter image description here

rm(list=ls())
par(mfrow=c(2,1))
par(mar = c(4,4.5,1,1))

postscript(file="Test.eps", onefile = TRUE, horizontal = FALSE)
par(mfrow=c(2,1))
par(mar = c(4,4.5,1,1))

x <- seq(-pi, pi, by=0.1)
y1<-abs(cos(x)); y2<-abs(sin(x))
m<-cbind(x,y1,y2,y1+y2,abs(y1-y2))

matplot(m[,1],(m[,c(2,3,4)]), type="l", lty=c(1,2,3,4),ylim=c(0,max(unlist(m[,2:5]))),
        xaxt="n",xlab="Time",ylab="Y",lwd=2,col=c("black","black","black","black"))
axis(1,c(-pi,-pi/2,0,pi,pi/2),expression(-pi,-pi/2,0,pi,pi/2))
legend("topright", expression("y"[1],"y"[2],"y"[1]+"y"[2],"y"[1]-"y"[2]),lty=c(1,2,3,4),lwd=2,col="black")

matplot(m[,1],(m[,c(2,3,5)]), type="l", lty=c(1,2,3,4),ylim=c(0,max(unlist(m[,2:5]))),
        xaxt="n",xlab="Time",ylab="Y",lwd=2,col=c("black","black","black","black"))
axis(1,c(-pi,-pi/2,0,pi,pi/2),expression(-pi,-pi/2,0,pi,pi/2))
legend("topright", expression("y"[1],"y"[2],"y"[1]+"y"[2],"y"[1]-"y"[2]),lty=c(1,2,3,4),lwd=2,col="black")


par(mfrow=c(1,1))
graphics.off()