Skip to content
Prev 69755 / 398525 Next

How to make label in multi plot

Hi

(cc'ed to Pierre Lapointe because this should answer the question about 
"[R] Centered overall title with layout()" as well)
Muhammad Subianto wrote:
Two ways (at least):

(i)  use an outer margin ...

ooma <- par(oma=c(0, 5, 0, 0))
layout(rbind(c(1, 2, 3),
              c(0, 4, 0)))
plot(1:10, main="Plot 1")
olas <- par(las=2)
mtext("Group A", side=2, adj=1, outer=TRUE,
       at=0.75)
par(olas)
plot(1:20, main="Plot 2")
plot(1:30, main="Plot 3")
plot(1:40, main="Plot 4")
olas <- par(las=2)
mtext("Group B", side=2, adj=1, outer=TRUE,
       at=0.25)
par(olas)
# new page!
plot(1:40, main="Plot 5")
par(ooma)

(ii) create an extra row/coloumn in the layout for the labels:

layout(rbind(c(1, 2, 3, 4),
              c(5, 0, 6, 0)),
        widths=c(2, 5, 5, 5))
# "plot 1" is label for row 1
omar <- par(mar=rep(0, 4))
plot.new()
text(0.5, 0.5, "Group A", cex=2)
par(omar)
plot(1:10, main="Plot 1")
plot(1:20, main="Plot 2")
plot(1:30, main="Plot 3")
# "plot 5" is label for row 2
omar <- par(mar=rep(0, 4))
plot.new()
text(0.5, 0.5, "Group B", cex=2)
par(omar)
plot(1:40, main="Plot 4")
# new page!
plot(1:40, main="Plot 5")


Paul