[R] multiple plots per page using hist and pdf

Ben Tupper PemaquidRiver at tidewater.net
Wed Feb 27 17:31:21 CET 2008


Hello,

I am puzzled by the behavior of hist() when generating multiple plots  
per page on the pdf device. In the following example two pdf files  
are generated. The first results in 4 plots on one pdf page as  
expected.  However, the second, which swaps one of the plot() calls  
for hist(), results in a 4 page pdf with one plot per page.

How might I get the histogram with 3 other scatter plots onto a  
single pdf page?

platform       powerpc-apple-darwin8.10.1
version.string R version 2.6.1 (2007-11-26)

Thanks!
Ben

###BEGIN
data(iris)

orig.par = par(no.readonly = TRUE)

pdf(file = "just_plots.pdf")

par(mfrow=c(2,2))

plot(iris$Sepal.Length, iris$Sepal.Width, main = "Plot 1")
plot(iris$Petal.Length, iris$Petal.Width, main = "Plot 2")
plot(iris$Sepal.Length, iris$Petal.Length, main = "Plot 3")
plot(iris$Sepal.Width, iris$Petal.Width, main = "Plot 4")

dev.off()

pdf(file = "hist_and_plots.pdf")

hist(iris$Sepal.Length, main = "Plot 1")
plot(iris$Petal.Length, iris$Petal.Width, main = "Plot 2")
plot(iris$Sepal.Length, iris$Petal.Length, main = "Plot 3")
plot(iris$Sepal.Width, iris$Petal.Width, main = "Plot 4")

dev.off()


par(orig.par)
###END

Ben Tupper
PemaquidRiver at tidewater.net

I GoodSearch for Ashwood Waldorf School.

Raise money for your favorite charity or school just by searching the  
Internet with GoodSearch - www.goodsearch.com - powered by Yahoo!



More information about the R-help mailing list