I am working with the R programming language. I made the following graph using the built-in "mtcars" dataset:
library(ggplot2)
a = ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle("mtcars: wt vs mpg")
Question: Now, I am trying to customize the title, but I want the title to "contain a variable reference", for example:
b = ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle("mtcars: wt vs mpg - average mpg = mean(mtcars$mpg)")
But this command literally just prints the code I wrote:
I know that the "mean" command runs by itself:
mean(mtcars$mpg)
[1] 20.09062
But can someone please help me change this code:
ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle("mtcars: wt vs mpg - average mpg = mean(mtcars$mpg)")
So that it produces something like this (note: here, I manually wrote the "mean" by hand):
Thanks


