2

I made a matrix of figures using par(mfrow = (3, 4)). Now I want to overlay each row with texts like this: enter image description here

What is the simplest way to achieve this?

Thank you!

user2961927
  • 1,290
  • 1
  • 14
  • 22
  • Check this: https://www.r-bloggers.com/adding-text-to-r-plot/ – sm925 Nov 14 '19 at 19:44
  • See if [this](https://stackoverflow.com/questions/11198767/how-to-annotate-across-or-between-plots-in-multi-plot-panels-in-r) helps. – Rui Barradas Nov 14 '19 at 19:52
  • @samadhi Thank you for sharing the blog. I am familiar with the layout techniques and understand every code in the blog, but still cannot think of how it would solve my problem? Here I want to add texts across panels, like on the background where I would add transparency, not in between panels or on a single panel – user2961927 Nov 14 '19 at 19:57
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Nov 14 '19 at 22:14

1 Answers1

1

OPTION 1

Add the text after plotting all figures:

par(list(mfrow = c(3, 4),
         mar=c(2,2,1,1)))
lapply(1:12,FUN=function(x) plot(1:100,runif(100),cex=0.2))

##You will have to manually adjust these values to fit your figure
xval = -150
yval = 0.5
y_incr = 1.59

text(x=xval, y=yval, labels="TextToAdd3",col=rgb(0,0,1,0.5), cex=3, xpd=NA)
text(x=xval, y=yval+y_incr, labels="TextToAdd2",col=rgb(0,0,1,0.5), cex=3, xpd=NA)
text(x=xval, y=yval+y_incr*2, labels="TextToAdd1",col=rgb(0,0,1,0.5), cex=3, xpd=NA)

enter image description here

OPTION 2 Centre caption on the left margin every time you plot in the third column. This means less stuffing around with manually adjusting values (plot looks the same as above):

par(list(mfrow = c(3, 4),
         mar=c(2,2,1,1)))

texts=list("TextToAdd1",
           "TextToAdd3",
           "TextToAdd3")

for(i in 1:12){
  plot(1:100,runif(100),cex=0.2)
  if((i+1)%%4==0){
    mtext(text=texts[[i/3]],side=2,line=par()$mar[2], las=1,col=rgb(0,0,1,0.5), cex=3,adj=0.5)
  }
}
drJones
  • 1,233
  • 1
  • 16
  • 24