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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With