[R] Multiple plots in a single page and stripplot()
Deepayan Sarkar
deepayan.sarkar at gmail.com
Thu Jun 17 11:38:29 CEST 2010
On Thu, Jun 17, 2010 at 12:57 PM, Lars Karlsson
<larsmkarlsson.53 at gmail.com> wrote:
> I want to make a 2x2 plot on a single page, using stripplot() and boxplot().
> I tried the following two alternatives with mfrow() and layout(), but none
> of them worked.
>
> library(lattice)
> par(mfrow=c(2,2))
> boxplot(X1 ~ Y, data=tst1, horizontal=T, las=1)
> boxplot(X2 ~ Y, data=tst1, horizontal=T, las=1)
> stripplot(Y ~ X1, data=tst1)
> stripplot(Y ~ X2, data=tst1)
> par(mfrow=c(1,1))
>
> nf <- layout(matrix(c(1,2,3,4), 2, 2, byrow=TRUE))
> layout.show(nf)
> boxplot(X1 ~ Y, data=tst1, horizontal=T, las=1)
> boxplot(X2 ~ Y, data=tst1, horizontal=T, las=1)
> stripplot(Y ~ X1, data=tst1)
> stripplot(Y ~ X2, data=tst1)
>
> What happens is that the two plots with boxplot() appears on one page, and
> each stripplot() appears on a single page.
>
> If I use stripchart() instead of stripplot() things works as expected (a 2x2
> plot on a single page).
>
> What to do to get a 2x2 plot using stripplot()?
Unless there are good reasons to do so, it's best not to mix
traditional and lattice (or other grid-based) graphics. You could
(1) use traditional graphics functions boxplot() and stripchart() as
you have already tried, or
(2) use lattice functions bwplot() and stripplot(). To learn how to
combine them in a single page, see ?print.trellis (par("mfrow") will
not work).
-Deepayan
More information about the R-help
mailing list