Description Usage Arguments Examples
plotsave()
is a convenient function for saving a plot. It also guesses the type of graphics device from the extension.
1 2 3 4 5 6 7 8 9 |
plot |
A myplot object to save |
file |
File name to create on disk.plot current window if NULL |
device |
Device to use (function or any of the recognized extensions,
e.g. |
path |
Path to save plot to (combined with filename). |
scale |
Multiplicative scaling factor. |
width, height |
Plot dimensions, defaults to size of current graphics device. |
units |
Units for width and height when specified explicitly (in, cm, or mm) |
dpi |
Resolution used for raster outputs. |
limitsize |
When |
... |
Other arguments passed on to graphics device |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ## Not run:
set.seed(1)
x=rnorm(100)
y=x*5+rnorm(100)
png(file="test1.png",units = "cm",width = 15, height = 15, units = "cm",res=300)
plot(x,y,pch=20)
lm=lm(y~x)
abline(lm,col="red")
points(x[1:5],y[1:5],col="blue",cex=1.5,pch=20)
dev.off()
pdf(file="test1.pdf")
plot(x,y,pch=20)
lm=lm(y~x)
abline(lm,col="red")
points(x[1:5],y[1:5],col="blue",cex=1.5,pch=20)
dev.off()
# myplot 1
p=myplot(set.seed(1),
x=rnorm(100),
y=x*5+rnorm(100),
plot(x,y,pch=20),
lm=lm(y~x),
abline(lm,col="red"),
points(x[1:5],y[1:5],col="blue",cex=1.5,pch=20))
plotsave(p)
plotsave(p,file="test2.png",width = 15, height = 15, units = "cm")
plotsave(p,file="test2.pdf",width = 150, height = 150, units = "mm")
# myplot 2
#using {} more convenient
rm(list=ls())
set.seed(1)
x=rnorm(100)
y=x*5+rnorm(100)
p=myplot({
plot(x,y,pch=20)
lm=lm(y~x)
abline(lm,col="red")
points(x[1:5],y[1:5],col="blue",cex=1.5,pch=20)
})
plotsave(p)
plotsave(p,file="test3.png",width = 15, height = 15, units = "cm")
plotsave(p,file="test3.pdf",width = 150, height = 150, units = "mm")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.