Reputation: 499
I am attempting to use the layout () function in R but am struggling to get the correct structure as I need a small plot graph along with a large 3d scatter plot in the same page. Currently the two are equal sized but are very squashed. I could allow the first graph to be reduced in size to allow more room for the larger plot, please excuse the rough diagram:
| 1 small | |graph | | |
| | | 1 large scatterplot | | | | | | |
Any ideas would be really appreciated
Upvotes: 0
Views: 2610
Reputation: 174778
The best way to understand layout()
is to plan out in your head or on paper a matrix of cells that cover the device and allocate cells to plots.
I suspect you want something like
m <- matrix(c(1,1,0,0,
1,1,0,0,
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2), ncol = 4, byrow = TRUE)
layout(m)
plot(1:10)
plot(rnorm(10000), rnorm(10000))
layout(1)
which gives
In this example, a 0
means the space is not used for the plot (as there is no way to create a zeroth plot, the first plot is plot 1), a 1
indicates where the first plot will go, and 2
the second plot.
You'll need to play about with dimensions of the device and/or whitespace in the margins (e.g. the top margin of each plot if you use no titles) to get more square layouts.
The layout.show()
function may also be of use as it shows the panels with a number indicating where each plot will go. For example:
layout(m)
layout.show(n = 2) ## next `n` plots
The other addition you can make is to specify the widths & height of the columns and rows of the specified matrix, relatively or absolutely, via the widths
and heights
arguments.
Upvotes: 3