MYaseen208
MYaseen208

Reputation: 23898

Automatically displaying the name of the variable in the title of the plot with ggplot2

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

Answers (1)

Brandon Bertelsen
Brandon Bertelsen

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

Related Questions