[R] Passing colnames to graphics title

John Fox jfox at mcmaster.ca
Wed Feb 16 17:38:17 CET 2005


Dear Laura,

It doesn't make sense to call colnames() with the loop index; you could do
something like (for the matrix or data frame X):

par(mfrow=c(1, ncol(X)))
names <- colnames(X)
for (i in seq(along=names)) hist(X[,i], main="", xlab=paste("Site:",
names[i]))

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Laura Quinn
> Sent: Wednesday, February 16, 2005 9:47 AM
> To: Uwe Ligges
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Passing colnames to graphics title
> 
> Obviously I have been trying to use the colnames() function!
> 
> However, when I try to subscript ie:
> 
> for(i in 1:20){
> main=paste("Site:",colnames(i),sep="")
> }
> 
> this doesn't work! I thought that as.character(colnames(i)) or
> substitute(colnames(i)) might work, but to no avail...
> 
> Laura Quinn
> Institute of Atmospheric Science
> School of Earth and Environment
> University of Leeds
> Leeds
> LS2 9JT
> 
> tel: +44 113 343 1596
> fax: +44 113 343 6716
> mail: laura at env.leeds.ac.uk
> 
> On Wed, 16 Feb 2005, Uwe Ligges wrote:
> 
> > Laura Quinn wrote:
> >
> > > Hi,
> > >
> > > Just a quick query - if I'm creating a function to 
> produce a number 
> > > of histograms per page of output (one per column from a 
> matrix), how 
> > > can I pass the column name of the matrix into the title 
> (or indeed 
> > > to form part of the x-axis label)?
> >
> >
> > By extracting them using colnames()?
> >
> > Uwe Ligges
> >
> >
> >
> > > TIA,
> > > Laura
> > >
> > > Laura Quinn
> > > Institute of Atmospheric Science
> > > School of Earth and Environment
> > > University of Leeds
> > > Leeds
> > > LS2 9JT
> > >
> > > tel: +44 113 343 1596
> > > fax: +44 113 343 6716
> > > mail: laura at env.leeds.ac.uk
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list 
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide! 
> > > http://www.R-project.org/posting-guide.html
> >
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list