[R] fancy text in pairs()

Charilaos Skiadas cskiadas at gmail.com
Thu May 15 04:04:57 CEST 2008


On May 14, 2008, at 9:28 PM, Michael.Scroggie at dse.vic.gov.au wrote:

> Dear List,
>
> I'm currently trying to produce a number of pairs() plots with special
> text labels in the diagonal panels giving the units for the various
> quantities.
> These labels stretch across multiple lines, with the names of the
> quantities
> and the symbols for the units on separate lines. This seems to be  
> leading
> to
> problems with the justification of the text that I can't seem to  
> work out.
>
>
> The code below gives an example of what I have in mind with some
> fake data and units to illustrate. Has anyone got some ideas on how
> to modify my code so that I can have both the name of the quantity and
> the symbol for the unit nicely centred within the diagonal panel, one
> above the
> other?
>
> I'm running R 2.7.0 under windows XP.
>
>
> #generate some fake data:
> x1<-rnorm(100, 10, 1)
> x2<-rnorm(100, 5, 1)
> x3<-rnorm(100, 100, 2)
> X<-cbind(x1, x2, x3)
>
>
> #character vector of labels..
> labs<-c(
>     expression(paste("Pressure \n", "(kg ", m^-2,")")),
>     expression(paste("Acceleration \n", "(", "m ", s^-1, s^-1,")")),
>     expression(paste("Concentration \n","(", mu, g," ", L^-1,")"))
>            )
>
> #make a pairs() plot of the data.
> pairs(X, labels=labs, las=1, label.pos=0.5)
>

Try this:

labs <- expression(atop(Pressure,(kg * m^-2)), atop(Acceleration, 
(m*s^-1*s^-1)),atop(Concentration,(mu*g*L^-1)))
pairs(X, labels=units, las=1, label.pos=0.5)

> Thanks for any solutions or suggestions,
>
> Michael Scroggie.
>

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list