Write R code to draw sample of size 100 from N(0,1) and N(5,1) each . Plot the two figures on the same graph.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()
It's not working.
Plots panel –> Export –> Save as Image or Save as PDF Specify files to save your image using a function such as jpeg(), png(), svg() or pdf(). Additional argument indicating the width and the height of the image can be also used.
To save multiple plots to the same page in the PDF file, we use the par() function to create a grid and then add plots to the grid. In this way, all the plots are saved on the same page of the pdf file. We use the mfrow argument to the par() function to create the desired grid.
we plot in R programming are displayed on the screen by default. We can save these plots as a file on disk with the help of built-in functions. It is important to know that plots can be saved as bitmap image (raster) which are fixed size or as vector image which are easily resizable.
dev. off shuts down the specified (by default the current) device. If the current device is shut down and any other devices are open, the next open device is made current.
It works for me.
Check the working directory for the Sample.pdf
file:
> getwd()
[1] "C:/Users/user2983722/Documents"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With