How to set plot page size in R?

The page size can be set by using the following line:

pdf("plot.pdf", width=8,height=11)

The code above set the page size to 8 multiply 11, which is the letter size.

The following is a complete example.

# create a simple data frame
a <- c(1,2,3,4,5)
b <- c(1,2,3,4,4)
df <-data.frame(a,b)

# set up generated file name and page size. 
pdf("plot.pdf", width=8,height=11)

# set number of diagrams on one page
par(mfrow=c(2,2),mar=c(4,4,0.5,0.5), oma=c(1.5,2,1,1))

# plot 3 lines
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")
plot(df$a,df$b, type="l")

dev.off()

Leave a Comment