简体   繁体   English

R:绘制并保存在pdf文件中

[英]R :Plot and save in a pdf file

Write R code to draw sample of size 100 from N(0,1) and N(5,1) each . 写入R代码以从N(0,1)和N(5,1)各自绘制大小为100的样本。 Plot the two figures on the same graph.Save the graph as Sample.pdf in the working directory I . 在同一图表上绘制两个图形。将图形作为Sample.pdf在工作目录I

My attempt : 我的尝试:

 pdf("SampleGraph.pdf",width=7,height=5)
 x=rnorm(100)
 y=rnorm(100,5,1)
 plot(x,lty=2,lwd=2,col="red")
 lines(y,lty=3,col="green")
 dev.off()

It's not working. 它不起作用。

It works for me. 这个对我有用。

Check the working directory for the Sample.pdf file: 检查Sample.pdf文件的工作目录:

> getwd()
[1] "C:/Users/user2983722/Documents"

If your problem is the lack of green points on the plot, here is the fix: 如果你的问题是情节上缺少绿点,这里是修复:

plot(x,lty=2,lwd=2,col="red", ylim = c(min(x,y),max(x,y)))
points(y,lty=3,col="green")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM