title: Adding Title to ggplot from the dataset itself
body: <p>I am working with the R programming language. I made the following graph using the built-in &quot;mtcars&quot; dataset:</p>
  <pre><code>library(ggplot2)
  a = ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle(&quot;mtcars: wt vs mpg&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ICtbS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ICtbS.png" alt="enter image description here" /></a></p>
  <p><strong>Question:</strong> Now, I am trying to customize the title, but I want the title to &quot;contain a variable reference&quot;, for example:</p>
  <pre><code>b = ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle(&quot;mtcars: wt vs mpg - average mpg = mean(mtcars$mpg)&quot;)
  </code></pre>
  <p>But this command literally just prints the code I wrote:</p>
  <p><a href="https://i.stack.imgur.com/s8SKx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s8SKx.png" alt="enter image description here" /></a></p>
  <p>I know that the &quot;mean&quot; command runs by itself:</p>
  <pre><code> mean(mtcars$mpg)
  [1] 20.09062
  </code></pre>
  <p>But can someone please help me change this code:</p>
  <pre><code>ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + ggtitle(&quot;mtcars: wt vs mpg - average mpg = mean(mtcars$mpg)&quot;)
  </code></pre>
  <p>So that it produces something like this (note: here, I manually wrote the &quot;mean&quot; by hand):</p>
  <p><a href="https://i.stack.imgur.com/pqr7S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pqr7S.png" alt="enter image description here" /></a></p>
  <p>Thanks</p>