R: Schedule and save as a pdf file

Write an R code to draw a sample of size 100 from N (0,1) and N (5,1) each. Highlight two numbers on one chart. Save the graph as Sample.pdf in the working directory 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() 

Does not work.

+8
r
source share
2 answers

This works for me.

Check the working directory for the Sample.pdf file:

 > getwd() [1] "C:/Users/user2983722/Documents" 
+9
source share

If your problem is the lack of green dots on the chart, here's a fix:

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

All Articles