[R] multiple plots per page using hist and pdf
John Kane
jrkrideau at yahoo.ca
Thu Feb 28 00:28:03 CET 2008
I think you need to reset the par(mfrow=c(2,2)) before
plotting the second set of graphs.
--- Ben Tupper <PemaquidRiver at tidewater.net> wrote:
> 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!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
More information about the R-help
mailing list