[R] plot function / par() settings
Paul Johnson
pauljohn32 at gmail.com
Tue Apr 8 21:27:25 CEST 2008
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
More information about the R-help
mailing list