将图块保存为PDF后,传奇变得混乱

时间:2016-05-30 07:29:50

标签: r plot

我绘制了几个折线图。 但在将我的工作保存到pdf文件后。图例线运行><整个图变得凌乱~~ 我可以知道任何调整方法吗?

#test OF POOLED VARIANCE T TEST for  (100,100) GAMMA equal 
M <- c(1.0,1.5,2.0,2.5,3)
yt <- c(0.0509,0.0501,0.0487,0.0490,0.0510) 
yt1<-c(0.0493,0.0498,0.0547,0.0568,0.0580)
yt2<-c(0.0485,0.0513,0.0551,0.0556,0.0554)
yt3<-c(0.0518,0.0523,0.0588,0.0618,0.0625)
yt4<-c(0.0493,0.0552,0.0600,0.0607,0.0658)
plot(M, yt, type="l",col="green",xlab="Standard Deviation Ratio (SDR)", ylim = c(0.025, 0.145),
     ylab="Simulated Type I Error Rate",lwd=2)
abline(h=c(0.025,0.075),col=241,lty=3,lwd=2)

lines(M,yt1, lty=1,lwd=2,col="red")
lines(M,yt2,lty=1,lwd=2,col="purple4")
lines(M,yt3,lty=1,lwd=2,col="steelblue3")
lines(M,yt4, lty=1,lwd=2,col="gray27")

#test OF POOLED VARIANCE T TEST for  (10,10) GAMMA equal 
M <- c(1.0,1.5,2.0,2.5,3)
y <- c(0.0427,0.0529,0.0632,0.0672,0.0747) 
y1<-c(0.0421,0.0513,0.0714,0.0785,0.0920)
y2<-c(0.0422,0.0559,0.0767,0.0946,0.1063)
y3<-c(0.0346,0.0609,0.0873,0.1062,0.1248)
y4<-c(0.0334,0.0649,0.0988,0.1282,0.1433)
lines(M,y, lty=2,col="darkgreen",lwd=2)

lines(M,y1, lty=2,lwd=2,col="darkred")
lines(M,y2,lty=2,lwd=2,col="purple4")
lines(M,y3,lty=2,lwd=2,col="steelblue3")
lines(M,y4, lty=2,lwd=2,col="lightgoldenrod4")


legend("topleft",c("t(10,10,1.5)","t(10,10,2)",
"t(10,10,2.5)","t(10,10,3)","t(10,10,3.5)","t(100,100,1.5)","t(100,100,2)",
"t(100,100,2.5)","t(100,100,3)","t(100,100,3.5)"),
col=c("darkgreen","darkred","purple4","steelblue3","lightgoldenrod4","green","red","purple4",
"steelblue3","gray27"),lwd=c(2,2,2,2,2,2,2,2,2,2),lty=c(2,2,2,2,2,1,1,1,1,1),cex=0.77)

输出类似于以下enter image description here

如图所示,传说凌乱。我可以知道如何确保线路不运行吗?

1 个答案:

答案 0 :(得分:0)

  

我绘制了几个折线图。但在将我的工作保存到pdf文件后。图例线运行&gt;&lt;整个图形变得凌乱

这似乎说你在R图形窗口上的原始输出很好。如果要将绘图保存为pdf文件,请不要先在R图形窗口中生成它,然后保存。你应该立即在pdf文件上绘制它。使用以下内容:

pdf("myplot.pdf")  ## open a pdf file for plotting
## ... your R code for plotting
dev.off()  ## close pdf; you must do this!

输出pdf位于您的工作目录下。如果您不知道,请在R中执行getwd(),您将看到此路径。

如果您使用的是Microsoft Word,那么您可以尝试使用它:

jpeg("myplot.jpeg", quality = 100)  ## open a JPEG file for plotting; no quality loss
## ... your R code for plotting
dev.off()  ## close JPEG; you must do this!

这会将您的绘图输出为JPEG。您可以将其插入WORD,然后将其转换为pdf。你不应该再这样有问题了。