Skip to content
Prev 30700 / 398513 Next

layout.show()

Hi

layout.show() is only intended to be used to draw a diagram illustrating 
how the device is being split up into different figure regions by 
layout().  An example from help(layout) demonstrates what it does ...

      nf <- layout(matrix(c(1,1,0,2), 2, 2, byrow=TRUE), respect=TRUE)
      layout.show(nf)

The "n" parameter says how many of the figure regions to draw *in the 
diagram*.  So layout.show() is just there to help you to understand what 
layout() is doing.

For drawing a legend outside a plot, perhaps the following example may 
help (it is a modification of one of the examples in help(legend)) ...

     x <- seq(-pi, pi, len = 65)

     # layout with two columns; second one is 3cm wide
     layout(matrix(1:2, ncol=2),
            widths=c(1, lcm(3)))

     # plot;  goes in first column of layout
     plot(x, sin(x), type = "l", ylim = c(-1.2, 1.8), col = 3,
          lty = 2)
     points(x, cos(x), pch = 3, col = 4)
     lines(x, tan(x), type = "b", lty = 1, pch = 4, col = 6)
     title("legend(..., lty = c(2, -1, 1), pch = c(-1,3,4), merge=TRUE)",
           cex.main = 1.1)

     # legend (as separate plot);  goes in second column of layout
     par(mar=c(5.1, 0, 4.1, 0))
     plot.new()
     plot.window(0:1, 0:1)
     legend(0.5, 0.5,
            xjust=0.5, yjust=0.5,
            c("sin", "cos", "tan"),
            col = c(3, 4, 6),
            lty = c(2, -1, 1),
            pch = c(-1, 3, 4),
            merge = TRUE,
            bg = "gray90")
     par(mar=c(5.1, 4.1, 4.1, 2.1))


Hope that helps.

Paul
Wladimir Eremeev wrote: