plotsave: Save a myplot class with sensible defaults

Description Usage Arguments Examples

Description

plotsave() is a convenient function for saving a plot. It also guesses the type of graphics device from the extension.

Usage

1
2
3
4
5
6
7
8
9
plotsave(plot,file=NULL,
                device = default_device(file), 
                path = NULL, scale = 1, 
                width = par("din")[1], 
                height = par("din")[2], 
                units = c("in", "cm", "mm"),
                dpi = 300, limitsize = TRUE, 
                environment = parent.frame(),
                ...)

Arguments

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. "pdf"). By default, extracted from filename extension. plotsave currently recognises eps/ps, tex (pictex), pdf, jpeg, tiff, png, bmp, svg and wmf (windows only).

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 TRUE (the default), plotsave will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.

...

Other arguments passed on to graphics device

Examples

 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)

kumine/myplot documentation built on May 12, 2019, 3:14 p.m.