Friday, February 12, 2010

Plot layout in R

I recently needed to make a figure with two plots side-by-side. Plot 1 was to have a width 3 times that of plot 2. The layout feature in R seemed to be the answer. But, due to either lack of decent tutorials online or just plain bad luck in finding one, I found it rather difficult to understand how this layout function works. The usual help command help(layout) wasn't terribly helpful either. Here go the set of commands that really nailed it for me. Run them on your terminal to follow the rest of the blog.

nf <- layout(matrix(c(1,2),1,2),widths=c(1,1)); layout.show(nf)

Pretty straight forward isn't it? Now try,

nf <- layout(matrix(c(1,2),1,2),widths=c(3,1)); layout.show(nf)

Basically the matrix(c(1,2),1,2) is what contains the layout information. c(1,2) is simply the label of the plot in question. The 1,2 after that tells you the number if rows(1) and columns(2) in the layout. Now a little more complicated example,

nf <- layout(matrix(c(1,3,4,2,5,6,7,8),2,4),widths=c(1,1,1,5)); layout.show(nf)

Hope this helps.

No comments:

Post a Comment