Consider for both the situations:
1. Image will be generated in future in my R script. So, how do I save it to disk?
To save your required plot, you need to do the following:
- Open a device, using png(), bmp(), pdf() or similar
- Plot your model
- Close the device using dev.off()
Below is the example code for saving the plot in png format
required_fit <- lm(some ~ model)
png(filename="your/file/location/name.png")
plot(required_fit)
dev.off()
All these are described in the help page. To know about the formats, you just have to type ?pdf, ?png ,?jpeg
NOTE:
a.The image might look different on disk to the same plot directly plotted to your screen.
b.If your plot is made by either lattice or ggplot2 you have to print the plot.
2 . The plot is already plotted and I just want to copy it as it is to a disk .
dev.print(pdf, 'filename.pdf')
The above command should copy the image.
For any other formats, you can, replace pdf with other file types such as png, jpeg etc.