Re: [R] plot function / par() settings

From: Paul Johnson <pauljohn32_at_gmail.com>
Date: Tue, 08 Apr 2008 14:27:25 -0500

On Tue, Apr 8, 2008 at 12:47 PM, Pedro Mardones <mardones.p_at_gmail.com> wrote:
> Dear all;
>
> I'm trying to create a 2 x 3 plot (something I know like lattice can
> do better) using the plot function. However; I'm not sure how to make
> the width of the plots to be the same on each column. I guess the
> answer maybe obvious but I haven't been able to figure it out. I'll
> appreciate any suggestion. Here is the (highly inefficient) code for
> the first row:
>
Dear Pedro:

I played around with the layout function and I think this does what you want. Because I set the widths exactly, there is no "squishing" of the outer plots anymore.

Try this:

nf <- layout(matrix(c(1,2,3,4,5,6),2,3,byrow=TRUE), widths=c(lcm(5), lcm(5), lcm(5)), heights=c(1,1), TRUE)

layout.show(nf)

par(mar=c(1,0,0,0))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", col = "blue");   axis(3, at = seq(1:5), labels = rep("", 5))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =   "red"); axis(3, at = seq(1:5), labels = seq(1:5))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =   "red"); axis(3, at = seq(1:5), labels = rep("", 5))   axis(4, at = seq(1:5), labels = rep("", 5))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", col = "blue");   axis(3, at = seq(1:5), labels = rep("", 5))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =   "red"); axis(3, at = seq(1:5), labels = seq(1:5))

  plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =   "red"); axis(3, at = seq(1:5), labels = rep("", 5))   axis(4, at = seq(1:5), labels = rep("", 5))

>
> par(mfrow = c(2, 3))
> par(omi = c(0.60, 0.60, 0.60, 0.10))
>
> par(mai = c(0.00, 0.50, 0.50, 0.00))
> plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", col = "blue");
> axis(3, at = seq(1:5), labels = rep("", 5))
>
> par(mai = c(0.00, 0.00, 0.50, 0.00))
> plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =
> "red"); axis(3, at = seq(1:5), labels = seq(1:5))
>
> par(mai = c(0.00, 0.00, 0.50, 0.50))
> plot(1:5, 1:5, xlab = "", ylab = "", xaxt = "n", yaxt = "n", col =
> "red"); axis(3, at = seq(1:5), labels = rep("", 5))
> axis(4, at = seq(1:5), labels = rep("", 5))
>
> Thanks
> PM
>
> ______________________________________________
> 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.
>

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

______________________________________________
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.
Received on Tue 08 Apr 2008 - 19:29:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Apr 2008 - 19:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive