Reputation: 23898
I wonder how to automatically display the variable name of the title of the plot with ggplot2. Like in the example below how can I show the names of variables in the main title?
qplot(mpg, wt, data=mtcars, main = "Scatter plot of mpg vs wt")
Upvotes: 3
Views: 2163
Reputation: 44648
There's no hidden variable here, you can create a wrappper for qplot to accomplish this:
scatter.qplot <- function(x, y, d) {
qplot(get(x),get(y),data=get(d),main=paste("Scatter plot of",x,"vs",y,sep=" "))
}
scatter.qplot("mpg","wt","mtcars")
Upvotes: 3