adelmaas@MUSC.EDU
2004-Sep-20 14:00 UTC
[R] Getting the real names of variables within functions
Greetings. These days I find myself writing a lot of functions to handle routine things. One of these is a function to create a scatterplot of variables and draw a lowessed line so I can get some idea if there's any relationship between them. lowessed.plot <- function(x, y) { plot(x, y) lines(lowess(x, y)) } However, there's a slight problem: the plot axes come out labeled "x" and "y", which isn't what I want. I want the plot axes labeled with the names of the variables I passed into lowessed.plot for x and y. Is there any way to do that? Thanks in advance for any help anyone can provide. Aaron ----- Aaron Solomon?? (??ben Saul Joseph??) ??Adelman E-mail??: ??adelmaas at musc.edu Web site??: ??http??://??people.musc.edu??/??~adelmaas??/?? AOL Instant Messenger?? & ??Yahoo??! ??Messenger: ??Hiergargo (YM account now sometimes with the World's first statistical Webcam, Moran's Eye) AIM chat-room (preferred): Adelmania
Dimitris Rizopoulos
2004-Sep-20 14:09 UTC
[R] Getting the real names of variables within functions
Hi Aaron, try to use: plot( x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)) ) I hope it helps. 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/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: <adelmaas at MUSC.EDU> To: "list" <r-help at stat.math.ethz.ch> Sent: Monday, September 20, 2004 4:00 PM Subject: [R] Getting the real names of variables within functions> Greetings. > > These days I find myself writing a lot of functions to handle > routine things. One of these is a function to create a scatterplot > of variables and draw a lowessed line so I can get some idea if > there's any relationship between them. > > lowessed.plot <- function(x, y) > { plot(x, y) > lines(lowess(x, y)) > } > > However, there's a slight problem: the plot axes come out labeled > "x" and "y", which isn't what I want. I want the plot axes labeled > with the names of the variables I passed into lowessed.plot for x > and y. Is there any way to do that? Thanks in advance for any help > anyone can provide. > > Aaron > > ----- > Aaron Solomon?? (??ben Saul Joseph??) ??Adelman > E-mail??: ??adelmaas at musc.edu > Web site??: ??http??://??people.musc.edu??/??~adelmaas??/?? > AOL Instant Messenger?? & ??Yahoo??! ??Messenger: ??Hiergargo (YM > account now sometimes with the World's first statistical Webcam, > Moran's Eye) > AIM chat-room (preferred): Adelmania > > ______________________________________________ > 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 >
Duncan Murdoch
2004-Sep-20 14:10 UTC
[R] Getting the real names of variables within functions
On Mon, 20 Sep 2004 10:00:19 -0400, adelmaas at MUSC.EDU wrote :>Greetings. > >These days I find myself writing a lot of functions to handle routine >things. One of these is a function to create a scatterplot of >variables and draw a lowessed line so I can get some idea if there's >any relationship between them. > >lowessed.plot <- function(x, y) >{ plot(x, y) > lines(lowess(x, y)) >} > >However, there's a slight problem: the plot axes come out labeled "x" >and "y", which isn't what I want. I want the plot axes labeled with >the names of the variables I passed into lowessed.plot for x and y. Is >there any way to do that? Thanks in advance for any help anyone can >provide.You could do this with plot(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) But it's better to add two arguments to the function with those as default values, then pass them on to plot(); that way you can change the labels if you want. And add dots for other customization. For example, lowessed.plot <- function(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)), ...) { plot(x, y, xlab=xlab, ylab=ylab, ...) lines(lowess(x, y)) } Duncan Murdoch