Hi, Can we attach a more descriptive "label" (I may use the wrong terminology, which would explain why I found nothing on the FAQ) to variable names, and later have an easy way to switch to these labels in plots? I fear this is not possible and one must enter this by hand as ylab and xlab when making plots. Thanks in advance, Denis Chabot ------------------------------------------------------------------------ --------------------------- Denis Chabot, Ph.D. Chercheur en bio?nerg?tique Bioenergetics researcher Institut Maurice-Lamontagne Institut Maurice-Lamontagne P?ches et Oc?ans Canada Fisheries & Oceans Canada CP 1000, Mont-Joli, QC PB 1000, Mont-Joli, QC G5H 3Z4 G5H 3Z4 Canada Canada (418) 775-0624 (418) 775-0624 http://www.qc.dfo-mpo.gc.ca/iml
Hi Denis,
maybe something like this could be helpful:
x <- rnorm(20, 75); attr(x, "label") <- "Weight of
Males"
y <- rnorm(20, 60); attr(y, "label") <- "Weight of
Females"
plot. <- function(x, y, ...) plot.default(x, y, xlab=attr(x,
"label"),
ylab=attr(y, "label"), ...)
############
plot(x, y)
plot.(x, y)
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Denis Chabot" <chabotd at globetrotter.net>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, January 06, 2005 3:40 PM
Subject: [R] "labels" attached to variable names
> Hi,
>
> Can we attach a more descriptive "label" (I may use the wrong
> terminology, which would explain why I found nothing on the FAQ) to
> variable names, and later have an easy way to switch to these labels
> in plots? I fear this is not possible and one must enter this by
> hand as ylab and xlab when making plots.
>
> Thanks in advance,
>
> Denis Chabot
> ------------------------------------------------------------------------
> ---------------------------
> Denis Chabot, Ph.D.
> Chercheur en bio?nerg?tique Bioenergetics researcher
> Institut Maurice-Lamontagne Institut Maurice-Lamontagne
> P?ches et Oc?ans Canada Fisheries & Oceans Canada
> CP 1000, Mont-Joli, QC PB 1000, Mont-Joli, QC
> G5H 3Z4 G5H 3Z4
> Canada Canada
>
> (418) 775-0624 (418) 775-0624
> http://www.qc.dfo-mpo.gc.ca/iml
>
> ______________________________________________
> 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
>
I use Frank Harrell's library Hmisc to do this, it is very convenient!>library(Hmisc) > label(myVar)<-"my variable"Anne ----- Original Message ----- From: "Denis Chabot" <chabotd at globetrotter.net> To: <r-help at stat.math.ethz.ch> Sent: Thursday, January 06, 2005 3:40 PM Subject: [R] "labels" attached to variable names> Hi, > > Can we attach a more descriptive "label" (I may use the wrong > terminology, which would explain why I found nothing on the FAQ) to > variable names, and later have an easy way to switch to these labels in > plots? I fear this is not possible and one must enter this by hand as > ylab and xlab when making plots. > > Thanks in advance, > > Denis Chabot > ------------------------------------------------------------------------ > --------------------------- > Denis Chabot, Ph.D. > Chercheur en bio?nerg?tique Bioenergetics researcher > Institut Maurice-Lamontagne Institut Maurice-Lamontagne > P?ches et Oc?ans Canada Fisheries & Oceans Canada > CP 1000, Mont-Joli, QC PB 1000, Mont-Joli, QC > G5H 3Z4 G5H 3Z4 > Canada Canada > > (418) 775-0624 (418) 775-0624 > http://www.qc.dfo-mpo.gc.ca/iml > > ______________________________________________ > 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
Denis Chabot <chabotd <at> globetrotter.net> writes: : : Hi, : : Can we attach a more descriptive "label" (I may use the wrong : terminology, which would explain why I found nothing on the FAQ) to : variable names, and later have an easy way to switch to these labels in : plots? I fear this is not possible and one must enter this by hand as : ylab and xlab when making plots. See ?comment . e.g. x <- 1:10 comment(x) <- "My X" y <- x*x comment(y) <- "My Y" plot(x, y, xlab = comment(x), ylab = comment(y)) Another possibility is 'label' in package Hmisc.
Denis Chabot wrote:> Hi, > > Can we attach a more descriptive "label" (I may use the wrong > terminology, which would explain why I found nothing on the FAQ) to > variable names, and later have an easy way to switch to these labels in > plots? I fear this is not possible and one must enter this by hand as > ylab and xlab when making plots. > > Thanks in advance, > > Denis ChabotTry library(Hmisc) ?label /Johan -- No virus found in this outgoing message. Checked by AVG Anti-Virus.
Denis Chabot wrote:> Hi, > > Can we attach a more descriptive "label" (I may use the wrong > terminology, which would explain why I found nothing on the FAQ) to > variable names, and later have an easy way to switch to these labels in > plots? I fear this is not possible and one must enter this by hand as > ylab and xlab when making plots. > > Thanks in advance, > > Denis ChabotThe Hmisc package supports this: label(x) <- 'Some Label' describe(x) # uses variable name and label plot(x, y, xlab=label(x)) Better: xYplot(x, y) # label used automatically And if you do units(x) <- 'whatever units of measurement' then xYplot, describe, and other Hmisc functions will include the units (in a different font on graphs or when using latex()). Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Thank you to the many helpful list members who answered. I am grateful to have been told about attr and about Hmisc. Actually Hmisc also brings me solutions to many things on my wish list! Cheers, Denis Le Vendredi, 7 janv 2005, ? 12:11 Europe/Paris, r-help-request at stat.math.ethz.ch a ?crit :> De: Denis Chabot <chabotd at globetrotter.net> > Date: Jeud 6 janv 2005 15:40:07 Europe/Paris > ?: r-help at stat.math.ethz.ch > Objet: [R] "labels" attached to variable names > > > Hi, > > Can we attach a more descriptive "label" (I may use the wrong > terminology, which would explain why I found nothing on the FAQ) to > variable names, and later have an easy way to switch to these labels > in plots? I fear this is not possible and one must enter this by hand > as ylab and xlab when making plots. > > Thanks in advance, > > Denis Chabot