On 04/01/2010 11:30 AM, noclue_ wrote:
I have written a function (see below) which encloses a boxplot. My function
"xbox" takes in a variable name (such as "age"), and do a boxplot. Now I
would like to add a title for the graph dynamically displaying the variable
name as part of title.
But, in reality, the title displays VALUES of my variable.
Obviously, sprintf does not work.
Can somebody shed light on how to solve my problem in properly displaying a
title ?
Thanks.
-----------------------------------------------------------------
xbox<- function(X)
{
boxplot(_expenses ~ X, data=my_tab,main=sprintf("title is %s",X))
}
xbox(age)
Use "deparse(substitute(X))" in the sprintf. This says: get the
expression passed as X, and convert it to text.
Duncan Murdoch
______________________________________________
R-help@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.