Dustin Fife
2012-Jul-09 22:15 UTC
[R] mfrow and centering plots when there's an odd number
Let me start with an example: par(mfrow=c(2,3)) for (i in 1:5){ x = rnorm(100) y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) plot(x,y) } Note that there's five plots and six spaces for those plots via mfrow, leaving one row empty. Is there a way to have the bottom two plots centered? I think it looks weird to have them left-justified. Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[alternative HTML version deleted]]
Highland Statistics Ltd
2012-Jul-09 22:25 UTC
[R] mfrow and centering plots when there's an odd number
Let me start with an example: par(mfrow=c(2,3)) for (i in 1:5){ x = rnorm(100) y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) plot(x,y) } Note that there's five plots and six spaces for those plots via mfrow, leaving one row empty. Is there a way to have the bottom two plots centered? I think it looks weird to have them left-justified. Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma AFZ: I copied and pasted this from section 7.8 of our Beginner's Guide to R. It can easily be adapted for your problem. > MyLayOut <- matrix(c(2, 0, 1, 3), nrow = 2, ncol=2, byrow = TRUE) > nf <- layout(mat = MyLayOut, widths = c(3, 1), heights = c(1, 3), respect = TRUE) > xrange <- c(min(Benthic$NAP), max(Benthic$NAP)) > yrange <- c(min(Benthic$Richness), max(Benthic$Richness)) > #First graph > par(mar = c(4, 4, 2, 2)) > plot(Benthic$NAP, Benthic$Richness, xlim = xrange, ylim = yrange, xlab = "NAP", ylab = "Richness") > #Second graph > par(mar = c(0, 3, 1, 1)) > boxplot(Benthic$NAP, horizontal = TRUE, axes = FALSE, frame.plot = FALSE, ylim = xrange, space = 0) > #Third graph > par(mar = c(3, 0, 1, 1)) > boxplot(Benthic$Richness, axes = FALSE, ylim = yrange, space = 0, horiz = TRUE) Alain -- Dr. Alain F. Zuur First author of: 1. Analysing Ecological Data (2007). Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. URL: www.springer.com/0-387-45967-7 2. Mixed effects models and extensions in ecology with R. (2009). Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9 3. A Beginner's Guide to R (2009). Zuur, AF, Ieno, EN, Meesters, EHWG. Springer http://www.springer.com/statistics/computational/book/978-0-387-93836-3 4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno. http://www.highstat.com/book4.htm Other books: http://www.highstat.com/books.htm Statistical consultancy, courses, data analysis and software Highland Statistics Ltd. 6 Laverock road UK - AB41 6FN Newburgh Tel: 0044 1358 788177 Email: highstat@highstat.com URL: www.highstat.com URL: www.brodgar.com [[alternative HTML version deleted]]
R. Michael Weylandt <michael.weylandt@gmail.com>
2012-Jul-09 23:03 UTC
[R] mfrow and centering plots when there's an odd number
Take a look at ?layout Michael On Jul 9, 2012, at 5:15 PM, Dustin Fife <fife.dustin at gmail.com> wrote:> Let me start with an example: > > par(mfrow=c(2,3)) > for (i in 1:5){ > x = rnorm(100) > y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) > plot(x,y) > } > > Note that there's five plots and six spaces for those plots via mfrow, > leaving one row empty. Is there a way to have the bottom two plots > centered? I think it looks weird to have them left-justified. Thanks in > advance for the help! > > -- > Dustin Fife > PhD Student > Quantitative Psychology > University of Oklahoma > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.