0

Suppose I have written a user defined function to create a histogram:

sunny <- function(x,nadia) {
attach(nadia)
hist(x,  main="x", col="sea green", border="white",breaks=100)
}

Now my problem is I would like to have the variable name displayed on the graph, which is not appearing. I tried with the main = option but is it is showing only the character x since it is in quotes. I would be really glad if some one could solve my issue. Thanks!

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
shejomamu
  • 141
  • 1
  • 12

1 Answers1

0

Indirectly your question can be answerd by use of the answer on the following stack overflow question:How to convert variable (object) name into String

Applied in your situation results in the following code:

sunny <- function(x,nadia) {
attach(nadia)
hist(x,  main=deparse(substitute(x)), col="sea green", border="white",breaks=100)
}
Community
  • 1
  • 1
Berecht
  • 1,035
  • 8
  • 22