Is the filename of the current data set used in Lattice (e.g. in xyplot()) available as a variable name ?
I want to include the data set name as a footnote to the graph and write a generic function that takes the name.
Thanks
Is the filename of the current data set used in Lattice (e.g. in xyplot()) available as a variable name ?
I want to include the data set name as a footnote to the graph and write a generic function that takes the name.
Thanks
Do you mean "how do I turn a variable name into a string"?
If so, use the magic incantation deparse(substitute(my_variable))
.
drawplot <- function(x, data)
{
dataname <- deparse(substitute(data))
xyplot(
x,
data = data,
main = dataname
)
}
drawplot(Sepal.Width ~ Sepal.Length, iris)
On second thoughts, that might be overthinking things. It's a little easier to go the other way: starting with the dataset name, and then retrieving the data with get
.
dataname <- "iris"
xyplot(
Sepal.Width ~ Sepal.Length,
data = get(dataname),
main = dataname
)