Re: [R] several common sub-axes within multiple plot area

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Sun, 27 Jun 2010 16:52:35 +1000

On 06/26/2010 11:20 PM, Karl Brand wrote:
> Dear List,
>
> I'd really appreciate tip's or code demonstrating how i can achieve some
> common axis labels integrated into a multiple plot.
>
> In my example (below), i'm trying to achieve:
>
> -a single "Results 1 (Int)" centered & btwn row 1 and row 2;
> -a single "Results 2 (Int)" centered & btwn row 2 and row 3; and,
> -a single "Results 3 (Int)" centered at the bottom, ie., below row 3.
>
> I played with mtext() and par(oma=... per this post-
>
> https://stat.ethz.ch/pipermail/r-help/2004-October/059453.html
>
> But have so far failed to achieve my goal. Can i succeed with something
> combined with the 'high level' plot() function? Or do i need to get
> specific with some low level commands (help!)?
>
Hi Karl,
Your request prompted me to have a look at the getFigCtr function in the plotrix package. All I had to do was to add an argument to adjust the proportion of the figure region that was calculated, and it will do what you want, I think. The new function will be in the next version.

getFigCtr<-function(pos=c(0.5,0.5)) {
  pars<-par(c("usr","mar","fin","pin"))
  pxspan<-diff(pars$usr[1:2])
  fxspan<-pxspan*pars$fin[1]/pars$pin[1]   figxctr<-
   pars$usr[1]-(fxspan-pxspan)*pars$mar[2]/(pars$mar[2]+pars$mar[4]) + fxspan*pos[1]
  pyspan<-diff(pars$usr[3:4])
  fyspan<-pyspan*pars$fin[2]/pars$pin[2]   figyctr<-
   pars$usr[1]-(fyspan-pyspan)*pars$mar[1]/(pars$mar[1]+pars$mar[3]) + fyspan*pos[2]
  return(c(figxctr,figyctr))
}

#my example:
dev.new()
plot.new()
library(plotrix)
par(mfrow=c(3,2))
#Graph 1:
plot(rnorm(20), rnorm(20),

      xlab = "",
      ylab = "Variable A",
      main = "Factor X")

#Graph 2:
plot(rnorm(20), rnorm(20),
      xlab = "",
      ylab = "Variable A",
      main = "Factor Y")

mtext("Results 1 (Int)",1,at=getFigCtr(c(0,0))[1],line=3) #Graph 3:
plot(rnorm(20), rnorm(20),
      xlab = "",
      ylab = "Variable B")

#Graph 4:
plot(rnorm(20), rnorm(20),
      xlab = "",
      ylab = "Variable B")

mtext("Results 2 (Int)",1,at=getFigCtr(c(0,0))[1],line=3) #Graph 5:
plot(rnorm(20), rnorm(20),
      xlab = "",
      ylab = "Variable C")

#Graph 6:
plot(rnorm(20), rnorm(20),
      xlab = "",
      ylab = "Variable C")

mtext("Results 3 (Int)",1,at=getFigCtr(c(0,0))[1],line=3)

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 27 Jun 2010 - 06:50:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jun 2010 - 02:30:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive