Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the name of a data frame

Tags:

r

I am writing a wrapper function for plotting several data frames:

gf <- function(dataframe){
  ggplot(dataframe, aes(x=Date, y=Close)) + 
  geom_point() + 
  ggtitle(nameofdataframe))

and I cannot figure out the last part, how to get the name of the data frame as a variable to use in ggtitle(). Please help.

like image 391
K Owen - Reinstate Monica Avatar asked Feb 11 '13 05:02

K Owen - Reinstate Monica


1 Answers

This will do it:

ggtitle(deparse(substitute(dataframe)))

deparse() converts the variable name to a character string, substitute() lets you use it in the plot.

like image 69
Andrew Avatar answered Sep 20 '22 20:09

Andrew